QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327903 | #1844. Cactus | fangzichang | AC ✓ | 358ms | 137204kb | C++17 | 2.5kb | 2024-02-15 15:28:11 | 2024-02-15 15:28:12 |
Judging History
answer
#include<bits/extc++.h>
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
//本代码含有小众情感元素,建议满 18 周岁后观看
#ifdef __unix__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
#define debug fprintf(stderr,"Tomoyo after ~It's a wonderful life!~\n")
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define Inf (int)INFINITY
#define inf 0x3f3f3f3f
#define pb push_back
#define ll long long
#define endl '\n'
#define y second
#define x first
using namespace std;
const int N=6e5+10;
void read(){};
template<class T1,class ...T2>
inline void read(T1& ret,T2&... rest){
ret=0;char c=getchar();bool f=false;
while(c<'0'||c>'9')f=c=='-',c=getchar();
while(c>='0'&&c<='9')ret=ret*10+c-'0',c=getchar();
f&&(ret=-ret),read(rest...);
}
#define cin(...) read(__VA_ARGS__)
template<class T>
inline void print(T x){
static int s[35],t=0;
bool f=x<0;if(f)x=-x;
do s[t++]=x%10,x/=10;while(x);
f&&putchar('-');while(t)putchar(s[--t]+'0');
}
set<int>nxt[N];
vector<pii>ans;
vector<int>stk,rt,t[N],tmp[N];
int n,m,flg,tot,cnt,dfn[N],low[N],r[N];
#define op(x) ans.pb({1,x})
void work(int u){
if(!(nxt[u].size()&1))return;
for(int v:nxt[u])tmp[u].pb(v),nxt[v].erase(u);
op(u),nxt[u].clear();
for(int v:tmp[u])work(v);
}
void Tarjan(int u,int fa){
low[u]=dfn[u]=++tot,stk.pb(u);
for(int v:nxt[u])if(v^fa){
if(!dfn[v]){
Tarjan(v,u),low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
t[++cnt].pb(u),t[u].pb(cnt);
for(int w=-1;w!=v;stk.pop_back())
t[cnt].pb(w=stk.back()),t[w].pb(cnt);
}
}
else low[u]=min(low[u],dfn[v]);
}
}
void dfs(int u,int fa){
for(int v:t[u])if(v^fa)dfs(v,u);
if(u>n){
//assert(t[u][0]==fa);
for(int i=1;i<(int)(t[u].size());i++)op(t[u][i]+(i&1)*n);
op(t[u][1]),op(t[u].back()+(t[u].size()&1)*n);
}
}
int main(){
cin(n,m),cnt=n;
for(int i=1,u,v;i<=m;i++)
cin(u,v),nxt[u].insert(v),nxt[v].insert(u);
for(int u=1;u<=n;u++)work(u);
for(int u=1;u<=n;u++)if(nxt[u].size())flg=1;
if(!flg){
print(0),putchar(' '),print(ans.size()),putchar(endl);
for(pii p:ans)print(p.x),putchar(' '),print(p.y),putchar(endl);
return 0;
}
ans.pb({2,0});
for(int u=1;u<=n;u++){
if(!nxt[u].size())op(u);
else if(!dfn[u])rt.pb(u),r[u]=1,Tarjan(u,0);
}
for(int u:rt)dfs(u,0),op(u);
print(0),putchar(' '),print(ans.size()),putchar(endl);
for(pii p:ans){
print(p.x);if(p.y)putchar(' '),print(p.y);
putchar(endl);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 63356kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 6 1 2 1 3 1 5 1 1
result:
ok You are right!
Test #2:
score: 0
Accepted
time: 7ms
memory: 61352kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 5 1 4 1 2 1 1 1 6 1 3
result:
ok You are right!
Test #3:
score: 0
Accepted
time: 305ms
memory: 102980kb
input:
300000 368742 1 143504 1 234282 2 91276 2 296320 3 274816 4 212293 4 258214 5 253489 5 295826 6 96521 6 252745 6 267103 6 269879 7 5293 7 295586 8 44304 8 57067 8 233291 9 190526 10 18682 11 7440 12 24695 12 172561 12 243692 12 280316 13 80152 13 268749 14 146394 14 207280 15 151280 15 226848 16 458...
output:
0 521873 1 3 1 274816 1 273658 1 217572 1 248509 1 231418 1 73094 1 117739 1 11855 1 48428 1 55953 1 121689 1 234392 1 181317 1 238712 1 77369 1 105062 1 6838 1 130659 1 8 1 44304 1 9 1 10 1 18682 1 63155 1 148043 1 194189 1 26612 1 1155 1 31020 1 108936 1 71065 1 77412 1 124995 1 126920 1 53663 1 4...
result:
ok You are right!
Test #4:
score: 0
Accepted
time: 228ms
memory: 108632kb
input:
221155 322762 1 16446 1 214165 2 22590 2 67599 2 77971 2 173665 3 93601 3 218260 4 78445 4 126476 5 85674 5 129671 6 105765 6 161364 7 16742 7 19554 7 28037 7 51308 7 57193 7 151371 7 173612 7 218897 8 50830 8 178401 9 36068 9 198155 10 31227 10 57914 11 104822 11 196836 12 57848 12 129309 13 17006 ...
output:
0 424372 2 1 306425 1 18651 1 85270 1 239806 1 400648 1 15798 1 179493 1 236953 1 384625 1 134059 1 163470 1 355214 1 432093 1 48536 1 210938 1 269691 1 296420 1 49349 1 221978 1 75265 1 823 1 357041 1 88288 1 135886 1 309443 1 360033 1 61018 1 138878 1 282173 1 353695 1 89956 1 132540 1 311111 1 30...
result:
ok You are right!
Test #5:
score: 0
Accepted
time: 327ms
memory: 128624kb
input:
299999 449997 1 135132 1 274953 2 18542 2 217508 3 47624 3 205183 4 121104 4 270541 5 117846 5 249889 6 272286 6 286376 7 63903 7 89777 8 153806 8 271509 9 49792 9 220343 10 4543 10 293635 11 99727 11 261001 12 29177 12 108823 13 119446 13 183797 14 210754 14 247874 15 53747 15 122774 15 179117 15 2...
output:
0 599998 2 1 410521 1 8522 1 110522 1 308521 1 345845 1 27017 1 45846 1 327016 1 539834 1 176379 1 239835 1 476378 1 596880 1 92150 1 296881 1 392149 1 587759 1 209539 1 287760 1 509538 1 528487 1 81765 1 228488 1 381764 1 560109 1 33648 1 260110 1 333647 1 583207 1 22595 1 283208 1 322594 1 544475 ...
result:
ok You are right!
Test #6:
score: 0
Accepted
time: 295ms
memory: 107752kb
input:
300000 399999 1 215446 1 231704 2 115181 2 170051 3 1993 3 176144 4 18113 5 34133 5 53137 6 163395 6 256615 7 39049 7 128932 8 193977 8 205442 9 2810 9 260471 10 169593 10 278417 11 56849 11 139915 12 78729 12 164991 13 55416 13 62164 14 195504 14 254962 15 41739 15 143315 16 61905 16 244260 16 2772...
output:
0 511052 1 4 1 16 1 18 1 22 1 202949 1 285958 1 29 1 30 1 26134 1 271021 1 32 1 123549 1 181630 1 103490 1 257757 1 26829 1 52124 1 64135 1 65458 1 71442 1 80024 1 233192 1 109574 1 81157 1 35 1 139478 1 250704 1 64740 1 52176 1 166094 1 224937 1 263467 1 100032 1 77446 1 226783 1 128106 1 200630 1 ...
result:
ok You are right!
Test #7:
score: 0
Accepted
time: 358ms
memory: 137204kb
input:
299999 449997 1 207233 1 249849 2 26483 2 120133 3 48410 3 154146 3 264694 3 276131 4 33119 4 235166 5 104107 5 256329 6 121201 6 153902 7 217994 7 249799 8 98561 8 149095 8 161763 8 244331 9 113135 9 263126 10 78235 10 93112 11 58805 11 104743 11 135998 11 140583 11 199748 11 227329 12 34054 12 124...
output:
0 599998 2 1 596237 1 15658 1 296238 1 315657 1 366689 1 21437 1 66690 1 321436 1 417215 1 59977 1 117216 1 359976 1 546989 1 142542 1 246990 1 442541 1 447558 1 101581 1 147559 1 401580 1 361235 1 11236 1 61236 1 311235 1 359753 1 47646 1 59754 1 347645 1 586713 1 4299 1 286714 1 304298 1 586536 1 ...
result:
ok You are right!
Test #8:
score: 0
Accepted
time: 267ms
memory: 120580kb
input:
280291 392867 1 18749 1 136817 2 63519 2 159662 2 172896 2 251761 3 1878 3 142748 4 203284 4 228584 5 15844 5 50208 6 136817 6 245137 7 64955 7 165499 8 136817 8 220201 9 136817 9 191205 10 136817 10 192877 11 139542 11 162473 12 57326 12 190877 13 33859 13 153427 14 110791 14 136817 15 16389 15 864...
output:
0 505446 2 1 525428 1 6 1 245137 1 280297 1 500492 1 8 1 220201 1 280299 1 471496 1 9 1 191205 1 280300 1 473168 1 10 1 192877 1 280301 1 391082 1 14 1 110791 1 280305 1 297487 1 26 1 17196 1 280317 1 485631 1 30 1 205340 1 280321 1 520731 1 31 1 240440 1 280322 1 319272 1 36 1 38981 1 280327 1 5180...
result:
ok You are right!
Test #9:
score: 0
Accepted
time: 295ms
memory: 129252kb
input:
292995 410094 1 71999 1 169963 2 98256 2 132856 3 132856 3 165225 4 82003 4 132856 5 132364 5 160935 6 35335 6 147436 7 132856 7 255985 8 132856 8 200164 9 4463 9 156552 10 2320 10 99646 11 132856 11 185279 12 110686 12 285870 13 73136 13 275400 14 121746 14 132856 15 153856 15 278178 16 83552 16 21...
output:
0 527196 2 1 470031 1 176921 1 177036 1 469916 1 482915 1 55598 1 189920 1 348593 1 448103 1 117870 1 155108 1 410865 1 497676 1 89043 1 204681 1 382038 1 481029 1 156010 1 188034 1 449005 1 541849 1 10689 1 248854 1 303684 1 371735 1 38698 1 78740 1 331693 1 476485 1 151364 1 183490 1 444359 1 5557...
result:
ok You are right!
Test #10:
score: 0
Accepted
time: 291ms
memory: 104076kb
input:
300000 403707 1 129294 1 278573 2 11106 2 129294 3 184237 3 221196 4 55817 4 100929 4 136405 4 238314 5 31450 5 186997 6 4795 7 129294 7 163574 8 61455 8 129294 9 21984 9 129294 10 231237 11 129294 11 228549 12 129294 12 224390 13 19505 13 26574 14 55849 14 98378 15 23106 16 4025 16 100577 17 67090 ...
output:
0 495571 1 6 1 10 1 231237 1 158616 1 69702 1 15 1 23106 1 19 1 20 1 68436 1 110694 1 14262 1 110432 1 247212 1 49549 1 244837 1 11639 1 141945 1 171293 1 25 1 26 1 37 1 90299 1 43 1 44 1 220797 1 7582 1 153915 1 210713 1 53091 1 36603 1 89991 1 60626 1 71253 1 140486 1 24893 1 7891 1 138920 1 22312...
result:
ok You are right!
Test #11:
score: 0
Accepted
time: 7ms
memory: 60616kb
input:
1 0
output:
0 0
result:
ok You are right!
Test #12:
score: 0
Accepted
time: 241ms
memory: 97728kb
input:
255596 313062 1 10655 1 15889 1 35851 1 220010 1 243820 2 236476 3 75462 3 240876 3 241881 4 164691 5 112681 6 31313 6 40322 6 89447 6 199617 7 78108 7 249785 8 180866 8 225929 9 26444 10 209074 11 108986 12 147579 12 165165 13 53313 13 182814 13 230088 14 124147 15 73182 15 98755 15 212191 16 98391...
output:
0 415963 1 1 1 10655 1 15889 1 220010 1 243820 1 216583 1 68743 1 101829 1 86887 1 2 1 3 1 75462 1 240876 1 241881 1 1722 1 4 1 5 1 9 1 10 1 209074 1 177824 1 11 1 108986 1 13 1 182814 1 14 1 124147 1 5520 1 9028 1 62318 1 72214 1 187645 1 116944 1 15 1 18 1 147217 1 195359 1 49875 1 37460 1 74697 1...
result:
ok You are right!
Test #13:
score: 0
Accepted
time: 249ms
memory: 115280kb
input:
244001 330353 1 33864 1 90721 1 120604 1 122898 1 195228 1 211057 2 9529 2 118870 3 35564 3 229469 4 81097 4 236945 5 47476 5 223470 6 46769 6 48597 7 49304 7 146411 7 154996 7 220507 8 14839 8 162760 9 85423 9 114698 10 4239 10 32108 10 39949 10 85700 11 160326 11 205183 12 25068 12 156392 13 13985...
output:
0 416708 2 1 378027 1 28386 1 134026 1 272387 1 416021 1 75559 1 172020 1 319560 1 314827 1 45512 1 70826 1 289513 1 342457 1 83901 1 98456 1 327902 1 314924 1 215201 1 256204 1 70923 1 12203 1 339365 1 38613 1 95364 1 282614 1 436224 1 165740 1 192223 1 409741 1 363887 1 48312 1 119886 1 292313 1 4...
result:
ok You are right!