QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#229772 | #7640. Colorful Cycles | ucup-team2303# | WA | 141ms | 81760kb | C++17 | 1.7kb | 2023-10-28 16:52:40 | 2023-10-28 16:52:41 |
Judging History
answer
// #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define PB emplace_back
// #define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) {rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1];}
const int N = 1e6;
int T, a, b, in[N + 5], vis[N + 5];
vi st[3][N + 5];
struct pii {int x, y, z;} s[N + 5];
bool find(int n) {
rep(i, 0, 2) for(int x : st[i][n]) vis[x] = i;
bool res = 0;
rep(i, 0, 2) for(int x : st[i][n]) {
rep(j, 0, 2) if(i != j) for(int y : st[j][x])
if(vis[y] != -1 && vis[y] != j && vis[y] != i) res = 1;
if(res) break;
}
rep(i, 0, 2) for(int x : st[i][n]) vis[x] = -1;
return res;
}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
memset(vis, -1, sizeof(vis));
for(cin >> T; T--; ) {
cin >> a >> b;
rep(i, 1, a) st[0][i].clear(), st[1][i].clear(), st[2][i].clear(), in[i] = 0;
int x, y, z;
rep(i, 1, b) {
cin >> x >> y >> z;
s[i] = pii {x, y, z};
++in[x], ++in[y];
}
rep(i, 1, b) {
auto [x, y, z] = s[i];
if(in[x] > in[y] || (in[x] == in[y] && x < y)) st[z - 1][x].PB(y);
else st[z - 1][y].PB(x);
}
bool ans = 0;
rep(i, 1, a) if(find(i)) {
ans = 1;
break;
}
ans ? cout << "Yes\n" : cout << "No\n";
}
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 81760kb
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: 141ms
memory: 79756kb
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 No No No No Yes Yes Yes Yes Yes Yes Yes No No No Yes No Yes No No Yes Yes No Yes No Yes No Yes No No Yes Yes Yes Yes No No Yes No No No Yes Yes Yes Yes No No No Yes Yes Yes No No No Yes No Yes Yes Yes No Yes No No Yes Yes Yes No Yes Yes Yes Yes Yes No No No No No Yes Yes No Yes No No No Yes No Y...
result:
wrong answer expected YES, found NO [2nd token]