QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186327 | #6421. Degree of Spanning Tree | C1942huangjiaxu | AC ✓ | 275ms | 25124kb | C++14 | 1.2kb | 2023-09-23 17:05:26 | 2023-09-23 17:05:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int T,n,m,dfn[N],fa[N],low[N],il[N],du[N],gl;
bool dl[N];
vector<int>e[N],g[N];
void tarjan(int x){
dfn[x]=++dfn[0],low[x]=il[x]=x;
for(auto v:e[x]){
if(!dfn[v]){
++du[x],++du[v];
g[x].push_back(v),fa[v]=x;
tarjan(v);
if(dfn[low[v]]<dfn[low[x]])low[x]=low[v],il[x]=il[v];
}else if(dfn[v]<dfn[low[x]])il[x]=x,low[x]=v;
}
if(du[x]>n/2)gl=x;
}
void solve(){
scanf("%d%d",&n,&m);
gl=dfn[0]=0;
for(int i=1;i<=n;++i)e[i].clear(),g[i].clear(),dfn[i]=low[i]=il[i]=fa[i]=du[i]=dl[i]=0;
for(int i=1,x,y;i<=m;++i){
scanf("%d%d",&x,&y);
e[x].push_back(y),e[y].push_back(x);
}
if(n==3)return puts("No"),void();
tarjan(1);
if(gl){
int ct=0;
for(auto v:g[gl])if(dfn[low[v]]<dfn[gl])++ct;
if(du[gl]-ct>n/2)return puts("No"),void();
}
puts("Yes");
for(auto v:g[gl])if(du[gl]>n/2&&dfn[low[v]]<dfn[gl]){
if(!dl[gl]&&du[il[v]]<n/2)dl[gl]=true;
else dl[v]=true;
printf("%d %d\n",low[v],il[v]);
--du[gl];
}
for(int i=1;i<=n;++i)for(auto v:g[i])if(!dl[v])printf("%d %d\n",i,v);
}
int main(){
scanf("%d",&T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8724kb
input:
2 6 9 1 2 1 3 1 4 2 3 2 4 3 4 4 5 4 6 4 6 3 4 1 3 2 3 3 3 1 2
output:
Yes 1 2 2 3 3 4 4 5 4 6 No
result:
ok 2 cases
Test #2:
score: 0
Accepted
time: 116ms
memory: 11656kb
input:
11140 10 15 9 6 5 7 6 5 2 3 7 5 7 5 3 10 9 7 5 5 9 1 7 5 2 8 7 5 4 3 6 2 9 19 3 7 3 9 2 8 2 8 3 6 5 1 1 8 8 9 8 3 4 8 5 5 3 1 4 3 1 3 8 6 1 3 7 4 4 3 8 8 12 20 10 2 5 5 2 4 3 3 3 3 5 11 9 2 5 5 7 12 11 3 3 3 3 5 5 3 3 1 4 6 7 11 6 8 4 5 6 12 6 5 8 18 4 2 4 3 2 4 2 4 4 3 4 8 2 2 6 7 2 4 6 2 1 4 8 7 4...
output:
Yes 1 9 2 3 2 8 3 10 3 4 5 7 6 5 6 2 9 6 Yes 1 5 1 8 3 7 3 6 7 4 8 2 8 9 9 3 Yes 1 3 2 10 2 9 3 11 4 2 4 6 5 4 6 8 6 12 11 5 12 7 Yes 1 4 2 6 4 2 5 3 6 7 7 8 7 5 Yes 1 5 2 3 3 4 5 6 6 7 7 8 7 9 9 2 Yes 1 9 1 6 1 7 2 10 2 3 2 5 6 2 6 4 10 8 Yes 1 7 2 6 3 2 4 3 5 4 7 5 Yes 1 13 5 4 6 2 6 12 7 10 8 7 8...
result:
ok 11140 cases
Test #3:
score: 0
Accepted
time: 275ms
memory: 25124kb
input:
5 100000 197799 37555 22723 91160 32701 6451 4416 43186 26432 9750 82955 28292 33907 91534 78442 17771 67061 40351 28116 21494 23114 34672 66640 72636 95093 13033 6538 53698 87837 79541 71230 53985 63500 84753 5378 67971 56748 90951 20169 4465 97293 18331 53564 41043 95738 48579 96439 90865 7526 391...
output:
Yes 1 79669 3 80631 3 29964 4 35140 5 54719 6 86612 8 32122 8 4586 8 87681 9 6925 9 69470 10 77057 11 23470 12 22222 14 640 15 66799 18 74022 19 76749 20 94378 21 38142 22 86985 23 21674 24 52259 25 68588 27 36521 27 42255 28 81313 31 95382 31 94162 32 71835 34 72903 36 44202 38 30993 38 88546 39 51...
result:
ok 5 cases
Test #4:
score: 0
Accepted
time: 136ms
memory: 17428kb
input:
5 100000 100000 98195 31806 98195 70169 92153 98195 98195 46320 94369 56771 94369 49988 74295 98195 33796 98195 89903 94369 98195 1814 82388 98195 10189 94369 98195 6267 29845 98195 22425 94369 6241 98195 98195 33204 66516 98195 94369 71364 26277 94369 94369 94722 94369 25349 14629 98195 9329 98195 ...
output:
Yes 98195 88570 1 98195 94369 56771 94369 49988 94369 89903 94369 10189 94369 22425 94369 71364 94369 26277 94369 94722 94369 25349 94369 37019 94369 92383 94369 23674 94369 60216 94369 17520 94369 32256 94369 52995 94369 84894 94369 57180 94369 53508 94369 97186 94369 36150 94369 88885 94369 25807 ...
result:
ok 5 cases
Test #5:
score: 0
Accepted
time: 242ms
memory: 19232kb
input:
5 100000 149998 50735 5447 50735 24875 15119 49666 50735 30352 44756 49555 26546 32695 98445 50735 71657 50735 92212 50735 50735 19382 30935 50735 43688 46767 54630 54562 31371 50735 48877 50735 78593 76833 74317 37258 50735 48236 67116 50735 36579 50735 37536 44353 50735 46602 35088 29568 86657 507...
output:
Yes 1 35019 2 15015 3 60958 4 40777 7 89814 9 63844 10 25168 11 1279 12 27968 16 41994 21 55906 24 39497 25 19097 26 64122 29 60031 31 23185 32 26308 33 93672 36 58110 37 40808 39 62266 40 40179 45 47821 48 5735 49 32405 50 1195 51 86843 52 64499 53 69181 54 18567 58 77463 60 13965 63 97942 64 91257...
result:
ok 5 cases
Test #6:
score: 0
Accepted
time: 97ms
memory: 15836kb
input:
11102 14 14 9 10 10 14 9 11 10 2 9 14 9 5 10 13 9 8 4 9 3 10 10 1 12 10 10 6 9 7 6 6 3 2 3 5 2 6 1 6 3 4 3 6 5 5 3 2 2 1 4 5 2 5 5 3 8 8 5 6 4 6 8 6 8 4 6 1 8 3 2 8 7 8 12 12 8 12 12 2 4 12 9 12 12 3 1 12 1 8 6 8 11 8 7 8 8 10 12 5 15 15 9 15 6 15 13 8 15 3 8 11 15 12 8 2 15 4 8 10 15 8 15 14 8 4 7 ...
output:
Yes 1 10 9 11 9 14 9 5 9 8 9 4 9 7 10 9 10 2 10 13 10 3 10 12 10 6 Yes 1 6 2 3 3 5 3 4 6 2 Yes 1 2 2 3 3 5 5 4 Yes 1 6 4 8 6 5 6 4 8 3 8 2 8 7 Yes 1 8 8 6 8 11 8 7 8 10 12 8 12 2 12 4 12 9 12 3 12 5 Yes 1 15 4 8 8 13 8 11 8 2 8 10 8 7 8 5 15 9 15 6 15 3 15 12 15 4 15 14 Yes 9 6 1 9 3 7 3 10 3 12 3 2...
result:
ok 11102 cases
Test #7:
score: 0
Accepted
time: 170ms
memory: 17140kb
input:
11102 14 19 9 3 3 6 8 3 2 14 7 3 11 3 13 9 3 14 3 5 2 3 7 4 1 10 13 3 4 3 3 1 3 10 12 8 11 6 3 12 11 15 9 11 10 7 1 2 9 6 11 2 11 10 8 11 11 5 3 8 11 4 11 3 11 7 1 11 5 4 6 11 5 6 1 2 4 3 3 5 1 3 5 4 3 2 12 16 8 11 12 10 12 3 5 7 12 5 1 12 9 4 12 2 6 12 12 8 10 1 12 11 7 12 12 9 3 2 4 12 6 7 3 1 6 3...
output:
Yes 1 10 3 9 3 6 3 8 3 7 3 14 3 5 6 11 7 4 8 12 9 13 10 3 14 2 Yes 1 2 2 11 5 4 8 3 9 6 10 7 11 9 11 10 11 8 11 5 Yes 1 2 2 3 3 4 4 5 Yes 1 10 3 2 5 7 8 11 9 4 12 10 12 3 12 5 12 6 12 8 12 9 Yes 1 5 3 6 3 2 3 5 6 4 Yes 1 6 1 5 1 4 4 3 5 2 Yes 1 2 2 6 3 10 4 11 6 3 6 9 6 7 6 4 7 5 9 8 Yes 1 4 5 6 5 4...
result:
ok 11102 cases
Test #8:
score: 0
Accepted
time: 100ms
memory: 9996kb
input:
100000 5 7 2 5 1 4 2 1 1 3 5 1 4 2 2 3 5 7 2 4 4 3 2 1 4 5 2 5 1 4 3 2 5 7 5 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