QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186306#6421. Degree of Spanning TreeC1924huangjiaxuWA 121ms12304kbC++141.1kb2023-09-23 16:38:242023-09-23 16:38:24

Judging History

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

  • [2023-09-23 16:38:24]
  • 评测
  • 测评结果:WA
  • 用时:121ms
  • 内存:12304kb
  • [2023-09-23 16:38:24]
  • 提交

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])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;
}

詳細信息

Test #1:

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

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: 121ms
memory: 12304kb

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 19, paticipant's deg[5] = 3 is too large