QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293002 | #7640. Colorful Cycles | bachbeo2007 | RE | 147ms | 26296kb | C++23 | 3.4kb | 2023-12-28 19:31:28 | 2023-12-28 19:31:29 |
Judging History
answer
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
const int base=131;
int n,m;
int num[maxn],low[maxn],pos;
vector<pii> edge[maxn];
pii e[maxn];
int col[maxn];
int cc[maxn];
bool check=false;
vector<int> st;
void check_cycle_bcc(vector<int> num){
vector<int> ver;
int all=0;
for(int id:num){
if(!cc[e[id].fi]) ver.push_back(e[id].fi);
if(!cc[e[id].se]) ver.push_back(e[id].se);
cc[e[id].fi]|=(1<<col[id]);
cc[e[id].se]|=(1<<col[id]);
all|=(1<<col[id]);
}
int cnt=0;
for(int u:ver) if(cc[u]!=2 && cc[u]!=4 && cc[u]!=8) cnt++;
if(cnt>=3 && all==14) check=true;
for(int id:num) cc[e[id].fi]=cc[e[id].se]=0;
}
void dfs(int u,int p){
low[u]=num[u]=++pos;
for(auto [v,id]:edge[u]){
if(v==p) continue;
if(!num[v]){
st.push_back(id);
dfs(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=num[u]){
vector<int> cur;
while(true){
int x=st.back();
cur.push_back(x);
st.pop_back();
if(x==id) break;
}
check_cycle_bcc(cur);
}
}
else{
low[u]=min(low[u],num[v]);
if(num[v]<num[u]) st.push_back(id);
}
}
}
void solve(){
cin >> n >> m;
pos=0;check=false;
for(int i=1;i<=n;i++){
num[i]=low[i]=0;
edge[i].clear();
}
for(int i=1;i<=m;i++){
int u,v;cin >> u >> v >> col[i];
e[i]={u,v};
edge[u].push_back({v,i});
edge[v].push_back({u,i});
}
dfs(1,0);
cout << (check?"Yes":"No") << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;cin >> test;
while(test--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16124kb
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: 147ms
memory: 14024kb
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: 104ms
memory: 15948kb
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: 125ms
memory: 15916kb
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: 127ms
memory: 14024kb
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: 132ms
memory: 14132kb
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: 129ms
memory: 16340kb
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: 0ms
memory: 14760kb
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: 0ms
memory: 16876kb
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: 19ms
memory: 26296kb
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: 24ms
memory: 25136kb
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 ...