QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508612 | #7640. Colorful Cycles | pandapythoner | WA | 141ms | 3608kb | C++23 | 3.0kb | 2024-08-07 18:04:02 | 2024-08-07 18:04:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())
const ll inf = 1e18;
mt19937 rnd(234);
struct edge {
int to, c;
};
int n, m;
vector<vector<edge>> g;
vector<vector<array<int, 3>>> components;
vector<int> h, fup;
vector<int> usd;
vector<array<int, 3>> cur_stack;
void dfs(int v, int mh, int p) {
fup[v] = h[v] = mh;
usd[v] = true;
int marker = len(cur_stack);
for (auto [to, c] : g[v]) {
if (to == p) continue;
if (usd[to]) {
fup[v] = min(fup[v], h[to]);
} else {
cur_stack.push_back({ v, to, c });
dfs(to, mh + 1, v);
fup[v] = min(fup[v], fup[to]);
if (fup[to] >= h[v] and len(cur_stack) > marker) {
components.push_back({});
while (len(cur_stack) > marker) {
components.back().push_back(cur_stack.back());
cur_stack.pop_back();
}
}
}
}
for (auto [to, c] : g[v]) {
if (to == p) continue;
if (h[to] < h[v]) cur_stack.push_back({ v, to, c });
}
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int t;
cin >> t;
rep(itr, t) {
cin >> n >> m;
g.assign(n, vector<edge>());
rep(i, m) {
int u, v, c;
cin >> u >> v >> c; --u; --v; --c;
g[u].push_back(edge{ v, c });
g[v].push_back(edge{ u, c });
}
h.resize(n);
fup.resize(n);
usd.assign(n, false);
components.clear();
cur_stack.clear();
dfs(0, 0, -1);
if (!cur_stack.empty()) {
components.push_back(cur_stack);
}
vector<array<int, 3>> usd_colors(n, array<int, 3>{0, 0, 0});
bool ok = false;
for (auto component : components) {
array<int, 3> total_usd{ 0, 0, 0 };
int good_vertices = 0;
for (auto [u, v, c] : component) {
total_usd[c] += 1;
good_vertices -= (!!usd_colors[u][0] + !!usd_colors[u][1] + !!usd_colors[u][2] >= 2);
good_vertices -= (!!usd_colors[v][0] + !!usd_colors[v][1] + !!usd_colors[v][2] >= 2);
usd_colors[u][c] += 1;
usd_colors[v][c] += 1;
good_vertices += (!!usd_colors[u][0] + !!usd_colors[u][1] + !!usd_colors[u][2] >= 2);
good_vertices += (!!usd_colors[v][0] + !!usd_colors[v][1] + !!usd_colors[v][2] >= 2);
}
if (good_vertices < 3) continue;
if (!!total_usd[0] + !!total_usd[1] + !!total_usd[2] < 2) continue;
ok = true;
break;
}
if (ok) cout << "Yes" << "\n";
else cout << "No" << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 3608kb
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 Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes No 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 Yes...
result:
wrong answer expected NO, found YES [13th token]