QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186289 | #6421. Degree of Spanning Tree | C1924huangjiaxu | WA | 116ms | 11844kb | C++14 | 1.5kb | 2023-09-23 16:15:24 | 2023-09-23 16:15:25 |
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,Fa;
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]=Fa=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);
}
tarjan(1);
if(gl){
bool fg=false;
int ct=0;
for(auto v:g[gl]){
if(dfn[low[v]]<dfn[gl]){
++ct;
if(low[v]!=fa[gl])fg=true;
}
}
if(du[gl]-ct>n/2||!fg&&(du[fa[gl]]+du[gl]-n/2>n/2)){
if(du[gl]-ct<=n/2){
for(auto v:e[gl])if(dfn[v]<dfn[fa[gl]]){
dl[gl]=true;
Fa=v;
break;
}
if(!Fa)return puts("No"),void();
}else return puts("No"),void();
}
}
puts("Yes");
if(Fa)printf("%d %d\n",Fa,gl);
for(auto v:g[gl])if(du[gl]>n/2&&dfn[low[v]]<dfn[fa[gl]]){
dl[v]=true;
printf("%d %d\n",low[v],il[v]);
--du[gl];
}
for(auto v:g[gl])if(du[gl]>n/2&&low[v]==fa[gl]){
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: 10572kb
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: -100
Wrong Answer
time: 116ms
memory: 11844kb
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:
wrong answer case 120, participant does not find a solution but the jury does