QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506467#6421. Degree of Spanning TreezmrzmrWA 283ms7636kbC++201.8kb2024-08-05 17:46:342024-08-05 17:46:36

Judging History

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

  • [2024-08-05 17:46:36]
  • 评测
  • 测评结果:WA
  • 用时:283ms
  • 内存:7636kb
  • [2024-08-05 17:46:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 5010;
const int M = 2e5+10;
int n,m;
int ans = 0 ;
int cnt = 0;
int cnt_tree ;
int inde[M] ;
int flag ;
struct edge{
	int x,y;
//	int w;
}a[M];
struct edge_tree{
	int x,y;
//	int w;
}e[M];

bool cmp(edge_tree a,edge_tree b)		//排序 
{
	if(a.x>b.x) return a.x<b.x;
	if(a.x == b.x) return a.y < b.y ;
}

int f[M];
int find(int x)		//并查集 
{
	if(f[x]==x) return x;
	return f[x] = find(f[x]);
}
void kru()
{
	for(int i = 1 ; i <= n ; i++ )		//并查集初始化 
	{
		f[i] = i ;   
		inde[i] = 0;
	}
//	sort(a+1,a+m+1,cmp);
	cnt_tree = 0 ;
//	inde[M] = {0};
	flag = 0;
	for(int i = 1; i <= m ; i++)
	{
		int eu = find(a[i].x);
		int ev = find(a[i].y);
		if(eu == ev) continue;
		e[++cnt_tree].x = min(a[i].x,a[i].y);
		e[cnt_tree].y = max(a[i].x,a[i].y);
		f[ev] = eu;
		if(cnt_tree==n-1)
		{
			break;
		}
	}
}
void slove()
{
	cin>>n>>m;
	for(int i = 1 ; i <= m ; i++ )
	{
		int x,y;//,z;
		cin>>x>>y;//>>z;
		a[i].x=x;
		a[i].y=y;   
	//	a[i].w=z;      
	}
/*	for(int i = 1 ; i <= n ; i++ )		//并查集初始化 
	{
		f[i] = i ;   
	}*/
	kru();
	sort(e+1,e+cnt_tree+1,cmp);
	for(int i = 1 ; i <= cnt_tree ; i++ )
	{
		inde[e[i].x]++;
		inde[e[i].y]++;
//		cout<<e[i].x<<" "<<e[i].y<<endl;
	}
	for(int i = 1 ; i <= cnt_tree + 1 ; i++ )
	{
		if( inde[i] > n/2 )
		{
			flag = 1 ;
			break;
		}
	}
/*	for(int i = 1 ; i <= cnt_tree + 1 ; i++ )
	{
		cout<<inde[i]<<" ";
		
	}*/
//	cout<<flag<<endl<<endl;
	if(flag == 0 )
	{
		cout<<"Yes"<<endl;
		for(int i = 1 ; i <= cnt_tree ; i++ )
			cout<<e[i].x<<" "<<e[i].y<<endl;
		return ;
	}
	else cout<<"No"<<endl;
}
int main()
{

	int tcase;
	cin>>tcase;
	while(tcase--)
	{
		slove();
	}
	return 0;
	
}

详细

Test #1:

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

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
1 3
1 4
4 5
4 6
No

result:

ok 2 cases

Test #2:

score: -100
Wrong Answer
time: 283ms
memory: 5756kb

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
2 3
5 6
5 7
6 9
1 9
2 8
3 4
2 6
3 10
Yes
1 5
3 6
3 7
2 8
1 8
3 9
4 8
8 9
Yes
1 3
2 4
2 9
2 10
5 11
3 11
4 5
4 6
6 8
7 11
7 12
Yes
2 4
3 4
1 4
2 6
4 8
6 7
5 7
Yes
2 3
3 4
1 5
5 6
5 7
5 9
2 9
7 8
Yes
2 3
2 6
1 9
2 10
4 6
1 6
2 5
1 7
8 10
Yes
1 3
4 5
5 7
1 7
2 6
6 7
Yes
1 4
1 6
2 8
3 12
1 13
7 8
6 ...

result:

wrong answer case 19, participant does not find a solution but the jury does