QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#229284 | #7640. Colorful Cycles | ucup-team180# | WA | 271ms | 3804kb | C++17 | 3.7kb | 2023-10-28 15:39:46 | 2023-10-28 15:39:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct extended_block_cut_tree{
int N, cnt;
vector<vector<int>> G;
extended_block_cut_tree(vector<vector<pair<int, int>>> &E){
N = E.size();
vector<int> next(N, -1);
vector<int> d(N, -1);
vector<int> imos(N, 0);
for (int i = 0; i < N; i++){
if (d[i] == -1){
d[i] = 0;
dfs1(E, next, d, imos, i);
}
}
cnt = 0;
G.resize(N + 1);
vector<bool> used(N, false);
for (int i = 0; i < N; i++){
if (d[i] == 0){
dfs2(E, d, imos, used, cnt, i);
}
if (E[i].empty()){
G[i].push_back(N + cnt);
G[N + cnt].push_back(i);
cnt++;
G.push_back({});
}
}
G.pop_back();
}
void dfs1(vector<vector<pair<int, int>>> &E, vector<int> &next, vector<int> &d, vector<int> &imos, int v){
for (pair<int, int> e : E[v]){
int w = e.second;
if (d[w] == -1){
d[w] = d[v] + 1;
next[v] = w;
dfs1(E, next, d, imos, w);
imos[v] += imos[w];
} else if (d[w] < d[v] - 1){
imos[v]++;
imos[next[w]]--;
}
}
}
void dfs2(vector<vector<pair<int, int>>> &E, vector<int> &d, vector<int> &imos, vector<bool> &used, int b, int v){
used[v] = true;
bool ok = false;
for (pair<int, int> e : E[v]){
int w = e.second;
if (d[w] == d[v] + 1 && !used[w]){
if (imos[w] > 0){
if (!ok){
ok = true;
G[v].push_back(N + b);
G[N + b].push_back(v);
}
dfs2(E, d, imos, used, b, w);
} else {
G[v].push_back(N + cnt);
G[N + cnt].push_back(v);
cnt++;
G.push_back({});
dfs2(E, d, imos, used, cnt - 1, w);
}
}
}
if (!ok && d[v] > 0){
G[v].push_back(N + b);
G[N + b].push_back(v);
}
}
int size(){
return G.size();
}
vector<int> &operator [](int v){
return G[v];
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (int i = 0; i < t; i++){
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> E(n);
for (int j = 0; j < m; j++){
int x, y, z;
cin >> x >> y >> z;
x--;
y--;
z--;
E[x].push_back(make_pair(z, y));
E[y].push_back(make_pair(z, x));
}
vector<bool> same(n, true);
for (int j = 0; j < n; j++){
int cnt = E[j].size();
for (int k = 0; k < cnt - 1; k++){
if (E[j][k].first != E[j][k + 1].first){
same[j] = false;
}
}
}
extended_block_cut_tree BCT(E);
int V = BCT.size();
vector<int> p(V, -1);
vector<int> d(V, 0);
queue<int> Q;
Q.push(0);
while (!Q.empty()){
int v = Q.front();
Q.pop();
for (int w : BCT[v]){
if (w != p[v]){
p[w] = v;
d[w] = d[v] + 1;
Q.push(w);
}
}
}
vector<int> mask(V, 0);
for (int j = 0; j < n; j++){
for (pair<int, int> e : E[j]){
int c = e.first;
int k = e.second;
if (d[j] == d[k] + 2){
mask[p[j]] |= 1 << c;
} else {
mask[p[k]] |= 1 << c;
}
}
}
vector<int> cnt(V, 0);
for (int j = 0; j < n; j++){
if (!same[j]){
for (int w : BCT[j]){
cnt[w]++;
}
}
}
bool ok = false;
for (int j = n; j < V; j++){
if (mask[j] == 7 && cnt[j] >= 3){
ok = true;
}
}
if (ok){
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: 3544kb
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: 271ms
memory: 3804kb
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 [3131st token]