QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#228073 | #7640. Colorful Cycles | ucup-team1209# | RE | 193ms | 44620kb | C++20 | 2.8kb | 2023-10-28 11:30:36 | 2023-10-28 11:30:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
#define sz 202020
typedef long long ll;
int n,m;
vector<pii>V[sz];
int dfn[sz],low[sz],cc;
stack<int>S;
int T;
vector<int>V2[sz<<1];
void dfs(int x,int fa) {
dfn[x]=low[x]=++cc; S.push(x);
for (auto [v,c]:V[x]) if (v!=fa) {
if (!dfn[v]) dfs(v,x),chkmin(low[x],low[v]);
else chkmin(low[x],dfn[v]);
}
if (fa&&low[x]>=dfn[fa]) {
int y; ++T;
do {
y=S.top(); S.pop();
V2[T].push_back(y),V2[y].push_back(T);
} while (y!=x);
V2[T].push_back(fa),V2[fa].push_back(T);
}
}
int fa[sz<<1],dep[sz<<1];
void dfs2(int x,int ff) {
fa[x]=ff,dep[x]=dep[ff]+1;
for (auto v:V2[x]) if (v!=ff) dfs2(v,x);
}
// namespace DSU {
// int fa[sz];
// int getfa(int x){return x==fa[x]?x:getfa(fa[x]);}
// void merge(int x,int y){fa[getfa(x)]=getfa(y);}
// void init(unordered_set<int>vert) {for (auto x:vert) fa[x]=x;}
// }
int check(vector<array<int,3>>E) {
unordered_map<int,int>mask; int M=0;
unordered_set<int>vert;
for (auto [x,y,z]:E) mask[x]|=1<<z,mask[y]|=1<<z,M|=1<<z,vert.insert(x),vert.insert(y);
if (M!=7) return 0;
int cc=0,X=-1,Y=-1;
for (auto [x,m]:mask) if (m==7) {
++cc;
if (X==-1) X=x;
else Y=X,X=x;
}
if (cc!=2) return 1;
for (auto x:vert) if (x!=X&&x!=Y&&__builtin_popcount(mask[x])!=1) return 1;
// rep(t,0,2) {
// DSU::init(vert);
// for (auto [x,y,z]:E) if (z==t) DSU::merge(x,y);
// for (auto x:vert) if (x!=X&&x!=Y&&DSU::getfa(x)==DSU::getfa(X)&&mask[x]!=(1<<t)) return 1;
// }
return 0;
}
vector<array<int,3>>E[sz<<1];
void clr() {
rep(i,1,n) V[i].clear(),dfn[i]=low[i]=cc=0;
rep(i,1,T) V2[i].clear(),E[i].clear(),fa[i]=dep[i]=0;
T=0;
}
void work() {
cin>>n>>m;
int x,y,z;
rep(i,1,m) cin>>x>>y>>z,--z,V[x].push_back({y,z}),V[y].push_back({x,z});
T=n;
dfs(1,0);
dfs2(1,0);
rep(x,1,n) for (auto [y,z]:V[x]) if (x<y) {
int _x=x,_y=y,ww=-1;
if (dep[_x]<dep[_y]) swap(_x,_y);
ww=fa[_x];
E[ww-n].push_back({x,y,z});
}
rep(i,1,T-n) if (check(E[i])) return clr(),cout<<"Yes\n",void();
cout<<"No\n",clr();
}
int main() {
file();
ios::sync_with_stdio(false),cin.tie(0);
int T; cin>>T;
while (T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 32036kb
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: 0
Accepted
time: 193ms
memory: 32288kb
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:
ok 100000 token(s): yes count is 92314, no count is 7686
Test #3:
score: 0
Accepted
time: 179ms
memory: 32212kb
input:
50000 10 15 6 2 1 4 7 1 10 3 1 10 9 2 4 5 1 3 4 1 4 6 2 5 3 1 4 9 1 3 9 3 1 2 1 9 2 3 8 10 2 8 6 1 6 1 1 10 15 4 9 3 7 10 2 1 2 1 10 4 2 4 7 2 6 5 2 6 1 1 9 10 1 6 3 3 7 8 3 9 1 1 7 9 3 1 7 3 4 8 1 8 6 3 10 15 4 1 2 4 2 1 6 7 3 6 2 2 10 8 2 1 9 1 2 8 1 5 10 3 9 6 2 9 10 1 8 4 1 2 7 3 6 8 1 1 3 1 4 6...
output:
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 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 Ye...
result:
ok 50000 token(s): yes count is 49364, no count is 636
Test #4:
score: 0
Accepted
time: 158ms
memory: 32148kb
input:
50000 10 20 1 9 2 2 6 3 4 3 2 3 10 1 5 10 2 10 6 2 6 7 2 7 4 1 10 1 1 4 10 1 3 9 2 2 9 2 1 3 1 3 2 1 3 6 3 5 3 2 3 8 2 5 1 3 5 2 2 9 6 1 10 20 5 10 3 5 4 2 6 4 2 4 3 2 1 7 2 1 2 2 10 6 3 7 4 2 1 4 3 8 10 3 10 2 1 7 2 1 1 6 3 9 4 2 8 1 1 10 9 2 8 6 1 5 9 3 9 8 3 1 10 2 10 20 9 5 1 9 8 3 10 2 2 6 2 3 ...
output:
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 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:
ok 50000 token(s): yes count is 49941, no count is 59
Test #5:
score: 0
Accepted
time: 162ms
memory: 32076kb
input:
1000 200 1000 42 68 2 101 170 2 79 159 2 65 106 3 82 28 2 92 196 3 28 37 1 5 103 1 93 183 1 117 119 3 48 127 3 139 70 2 68 100 2 95 104 1 123 134 1 65 142 2 54 69 3 45 63 1 38 60 3 142 130 2 117 36 3 43 89 2 41 143 2 49 47 1 91 130 2 151 7 1 194 149 1 24 85 2 157 41 2 177 132 2 145 40 3 124 138 2 11...
output:
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 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:
ok 1000 token(s): yes count is 1000, no count is 0
Test #6:
score: 0
Accepted
time: 191ms
memory: 32516kb
input:
1000 400 1000 372 17 2 321 365 2 357 136 3 185 231 1 359 328 1 142 164 1 75 280 2 55 6 2 37 329 3 259 302 3 222 304 3 70 130 1 114 120 2 314 291 1 396 41 2 77 111 2 35 275 3 348 145 3 346 2 2 351 158 2 173 172 2 68 122 1 147 11 3 160 391 1 30 360 2 120 174 3 145 296 3 170 311 1 107 313 1 282 211 1 3...
output:
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 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:
ok 1000 token(s): yes count is 1000, no count is 0
Test #7:
score: 0
Accepted
time: 188ms
memory: 32504kb
input:
1000 400 1000 372 17 2 321 365 2 357 136 2 185 231 2 359 328 2 142 164 2 75 280 2 55 6 1 37 329 1 259 302 2 222 304 2 70 130 2 114 120 2 314 291 1 396 41 2 77 111 2 35 275 2 348 145 1 346 2 1 351 158 1 173 172 1 68 122 1 147 11 1 160 391 2 30 360 1 120 174 2 145 296 2 170 311 2 107 313 1 282 211 1 3...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 1000 token(s): yes count is 0, no count is 1000
Test #8:
score: 0
Accepted
time: 4ms
memory: 33452kb
input:
1 5002 8025 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38 39 1 3...
output:
No
result:
ok NO
Test #9:
score: 0
Accepted
time: 3ms
memory: 33192kb
input:
1 5002 8241 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38 39 1 3...
output:
No
result:
ok NO
Test #10:
score: 0
Accepted
time: 27ms
memory: 44620kb
input:
1 50002 80241 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38 39 1...
output:
No
result:
ok NO
Test #11:
score: 0
Accepted
time: 38ms
memory: 43892kb
input:
1 50002 80241 41804 9985 3 41015 531 1 32475 43357 1 27804 45331 1 37830 10818 1 9140 8762 1 3221 23343 3 28197 44388 3 12185 41625 1 44450 9756 2 38350 14775 1 9757 19481 1 20858 17104 1 7807 24256 3 32044 37846 3 46885 27385 1 39738 9906 1 44158 35304 3 16289 43980 2 23066 24757 1 42969 19561 3 46...
output:
No
result:
ok NO
Test #12:
score: -100
Runtime Error
input:
1 455002 812001 313782 211383 2 408674 310967 1 3243 335360 3 401421 177274 3 308321 237341 2 96981 83503 3 72406 169080 3 33154 273727 1 213486 241588 3 45112 90708 1 445073 252383 1 337069 283893 1 183445 167972 1 147552 226440 1 139659 55742 3 237507 63881 1 315650 309664 1 25601 309502 3 103898 ...