[Special Judge] 写挂了
  • 板块学术版
  • 楼主New_hope
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/12 19:36
  • 上次更新2023/11/2 14:16:05
查看原帖
[Special Judge] 写挂了
416242
New_hope楼主2023/10/12 19:36

题意就是无向图中一条路径上不能有 >=3 个点是同色的,std交后全Wa。求调

#include<bits/stdc++.h>
#define _ (int)(2e5 + 4)
#include "testlib.h"

using namespace std;

int col[_];
vector<int> g[_];

void add(int u,int v) {
    g[u].push_back(v);
}
bool check(int n) {
    for(int i = 1; i <= n; i ++) {
        for(int v1 : g[i]) {
            for(int v2 : g[v1]) {
                if(col[i] == col[v1] && col[v1] == col[v2]) return false;
            }
        }
    }
    return true;
}
int main(int argc, char* argv[]) {
    registerTestlibCmd(argc, argv);
    int T = inf.readInt(); 
    
    for(int i = 1; i <= T; i ++) {
        int n = inf.readInt(), m = inf.readInt();
        for(int j = 1; j <= n; j ++) g[j].clear(), col[j] = 0;
        for(int j = 1; j <= m; j ++) {
            int u,v;
            u = inf.readInt(), v = inf.readInt();
            add(u,v), add(v,u);
        }
        for(int j = 1; j <= n; j ++) {
            col[j] = ouf.readInt(); 
        }
        if(!check(n)) {
            quitf(_wa, "The answer is wrong");
        }
    }
    quitf(_ok, "The answer is correct.");
}
2023/10/12 19:36
加载中...