QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#230118 | #7640. Colorful Cycles | ucup-team1198# | WA | 148ms | 30464kb | C++20 | 2.8kb | 2023-10-28 17:40:55 | 2023-10-28 17:40:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
const int MAXN = 1'000'100;
vector<pair<int, int>> G[MAXN];
int tin[MAXN];
int tup[MAXN];
int ttime = 0;
vector<int> bridges;
void dfs(int v, int p) {
tin[v] = ttime;
tup[v] = ttime;
++ttime;
for (auto [u, id] : G[v]) {
if (id == p)
continue;
if (tin[u] != -1) {
tup[v] = min(tup[v], tin[u]);
} else {
dfs(u, id);
if (tup[u] > tin[v]) {
bridges.emplace_back(id);
}
tup[v] = min(tup[v], tup[u]);
}
}
}
bool used[MAXN];
vector<int> comp;
void dfs_comp(int v) {
used[v] = true;
comp.emplace_back(v);
for (auto [u, id] : G[v]) {
if (!used[u])
dfs_comp(u);
}
}
void solve() {
int n, m;
cin >> n >> m;
vector<pair<pair<int, int>, int>> edges(m);
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
--a;
--b;
edges[i] = make_pair(make_pair(a, b), c);
G[a].emplace_back(b, i);
G[b].emplace_back(a, i);
}
vector<bool> is_bridge(m, false);
fill(tin, tin + n, -1);
ttime = 0;
for (int i = 0; i < n; ++i) {
if (tin[i] == -1)
dfs(i, -1);
}
for (int i : bridges) {
is_bridge[i] = true;
}
bridges.clear();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < G[i].size(); ++j) {
if (is_bridge[G[i][j].second]) {
swap(G[i][j], G[i].back());
G[i].pop_back();
--j;
}
}
}
fill(used, used + n, false);
bool ans = false;
for (int i = 0; i < n; ++i) {
if (!used[i]) {
dfs_comp(i);
int cnt_with_diff_color = 0;
bool have[3] = {false, false, false};
for (int v : comp) {
int cur_c = -1;
bool dif_color = false;
for (auto [u, id] : G[v]) {
int c = edges[id].second;
have[c - 1] = true;
if (cur_c == -1)
cur_c = c;
else if (c != cur_c)
dif_color = true;
}
cnt_with_diff_color += dif_color;
}
if (have[0] && have[1] && have[2] && cnt_with_diff_color > 2)
ans = true;
comp.clear();
}
}
for (int i = 0; i < n; ++i)
G[i].clear();
if (ans)
cout << "Yes\n";
else
cout << "No\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 29892kb
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: 148ms
memory: 30464kb
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 [131st token]