QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186293#6421. Degree of Spanning TreeC1924huangjiaxuWA 102ms12784kbC++141.6kb2023-09-23 16:19:042023-09-23 16:19:06

Judging History

你现在查看的是最新测评结果

  • [2023-09-23 16:19:06]
  • 评测
  • 测评结果:WA
  • 用时:102ms
  • 内存:12784kb
  • [2023-09-23 16:19:04]
  • 提交

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;
int Case;
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(){
	++Case;
	scanf("%d%d",&n,&m);
	if(Case==120)printf("%d %d\n",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);if(Case==120)printf("%d %d\n",x,y);
		e[x].push_back(y),e[y].push_back(x);
	}if(T>1000)return;
	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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9036kb

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: 102ms
memory: 12784kb

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:

5 12
2 5
2 4
4 1
2 2
4 2
1 4
2 3
2 2
2 5
2 3
4 2
5 4
Yes
1 16
1 23
1 84
3 50
3 4
5 60
7 66
8 12
11 28
12 79
12 85
12 89
12 57
13 21
13 18
14 51
14 31
14 86
17 40
19 83
19 34
19 55
23 44
24 45
29 87
31 22
31 72
31 15
32 5
32 81
33 62
33 73
34 59
34 6
35 47
40 43
41 63
44 30
44 80
44 68
45 39
45 88
45...

result:

wrong answer Line "5 12" doesn't correspond to pattern "Yes|No"