QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#374894 | #7640. Colorful Cycles | liuzhenhao09# | WA | 139ms | 16032kb | C++20 | 1.8kb | 2024-04-02 19:20:10 | 2024-04-02 19:20:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
int to,nxt,w;
}e[2000010];
int T,n,m,nE = 0,timer = 0,tp = 0,rt,oo = 0;
int hd[2000010],dfn[2000010],low[2000010],stk[2000010];
vector<int>ans[2000010];
int id[2000010];
void add(int u,int v,int w){
e[++nE] = (edge){v,hd[u],w};
hd[u] = nE;
}
void tarjan(int u){
dfn[u] = low[u] = ++timer;
stk[++tp] = u;
if(u == rt && !hd[u]){
ans[++oo].push_back(u);
return;
}
for(int i = hd[u]; i; i = e[i].nxt){
int v = e[i].to;
if(!dfn[v]){
tarjan(v);
low[u] = min(low[u],low[v]);
if(low[v] >= dfn[u]){
oo++;
int z;
do{
z = stk[tp--];
ans[oo].push_back(z);
}
while(z != v);
ans[oo].push_back(u);
}
}
else low[u] = min(low[u],dfn[v]);
}
}
int col[2000010];
signed main(){
scanf("%lld",&T);
while(T--){
for(int i = 1; i <= oo; i++) ans[i].clear();
oo = 0;
nE = 0;
scanf("%lld %lld",&n,&m);
for(int i = 1; i <= n; i++) hd[i] = dfn[i] = low[i] = id[i] = 0;
for(int i = 1,u,v,w; i <= m; i++) scanf("%lld %lld %lld",&u,&v,&w),add(u,v,w),add(v,u,w);
timer = 0;
for(int i = 1; i <= n; i++) if(!dfn[i]) tp = 0,rt = i,tarjan(i);
bool flag = 0;
for(int u = 1; u <= oo; u++){
int cnt[4];
cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
for(auto v : ans[u]) id[v] = u,col[v] = -1;
int cc = 0;
for(auto v : ans[u]){
for(int i = hd[v]; i; i = e[i].nxt){
int vv = e[i].to,w = e[i].w;
if(id[vv] != u) continue;
cnt[w]++;
if(col[u] == -1) col[u] = w;
else if(col[u] != w) cc++;
if(col[v] == -1) col[v] = w;
else if(col[v] != w) cc++;
}
}
if(cc >= 3 && cnt[1] && cnt[2] && cnt[3]) flag = 1;
}
puts(flag ? "Yes" : "No");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 16032kb
input:
2 3 3 1 2 3 2 3 1 1 3 2 5 6 1 2 1 2 3 1 1 3 2 3 4 3 3 5 3 4 5 3
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #2:
score: -100
Wrong Answer
time: 139ms
memory: 15912kb
input:
100000 7 10 7 2 2 6 4 2 6 1 2 7 1 3 3 4 1 6 7 1 2 6 3 3 1 2 5 3 1 2 1 1 7 10 5 7 3 7 1 1 4 6 3 6 3 1 3 4 3 4 2 2 3 2 3 1 3 3 3 7 1 1 4 2 7 10 5 6 3 3 5 2 7 2 3 7 3 3 1 2 2 4 3 2 7 4 2 6 1 2 2 6 1 7 5 2 7 10 7 1 3 7 5 3 6 4 1 7 6 1 1 4 1 3 4 2 2 7 2 1 3 1 3 5 3 5 1 3 7 10 6 7 2 3 4 3 1 4 2 5 3 2 7 4 ...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No ...
result:
wrong answer expected NO, found YES [490th token]