QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461640 | #7640. Colorful Cycles | serverrepairman | WA | 104ms | 30656kb | C++17 | 1.2kb | 2024-07-02 21:07:22 | 2024-07-02 21:07:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int t, n, m;
vector <pii> gan[1100000];
int sum[4][1100000];
int vis[1100000];
int cnt;
bool dfs(int now, int dep){
if(vis[now]){
bool ret = true;
for(int k=1;k<=3;k++)
ret &= (sum[k][dep]-sum[k][vis[now]-1])>0;
return ret;
}
vis[now] = dep;
for(int k=1;k<=3;k++)
sum[k][dep+1] = sum[k][dep];
for(pii nex: gan[now]){
sum[nex.second][dep+1]++;
if(dfs(nex.first, dep+1))
return true;
sum[nex.second][dep+1]--;
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while(t--){
cin >> n >> m;
cnt = 0;
for(int i=1;i<=n;i++){
vis[i]= 0;
gan[i].clear();
}
for(int i=0;i<m;i++){
int x, y, z;
cin >> x >> y >> z;
gan[x].push_back({y, z});
gan[y].push_back({x, z});
}
if(dfs(1, 1))
cout << "Yes\n";
else
cout << "No\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 29788kb
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: 104ms
memory: 30656kb
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 No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Ye...
result:
wrong answer expected YES, found NO [53rd token]