QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461644 | #7640. Colorful Cycles | serverrepairman | WA | 95ms | 37196kb | C++17 | 1.2kb | 2024-07-02 21:14:39 | 2024-07-02 21:14:40 |
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 prev, 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])if(prev != nex.first){
sum[nex.second][dep+1]++;
if(dfs(nex.first, now, 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=0;i<=n;i++){
vis[i]= 0;
sum[1][i]=sum[2][i]=sum[3][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, 0))
cout << "Yes\n";
else
cout << "No\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 37156kb
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: 95ms
memory: 37196kb
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 No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Y...
result:
wrong answer expected YES, found NO [65th token]