QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706413#9525. Welcome to Join the Online Meeting!2366503423WA 821ms79736kbC++141.5kb2024-11-03 11:11:242024-11-03 11:11:24

Judging History

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

  • [2024-11-03 11:11:24]
  • 评测
  • 测评结果:WA
  • 用时:821ms
  • 内存:79736kb
  • [2024-11-03 11:11:24]
  • 提交

answer

#include <bits/stdc++.h> 
using namespace std;
map <int,int> cha;
int find(int x)
{
	if(cha[x]==x) return x;
	return cha[x]=find(cha[x]);
}
int main()
{
	int n,m,k;cin>>n>>m>>k;
	map <int,bool> book;
	vector <pair<int,int>> a,b;
	for(int i=1;i<=n;i++) cha[i]=i;
	while(k--)
	{
		int x;cin>>x;
		book[x]=1;
	}
	while(m--)
	{
		int x,y;cin>>x>>y;
		a.push_back({x,y});
		if(book[x]!=1&&book[y]!=1) {cha[find(x)]=find(y);}
		else{b.push_back({x,y});}
	}
	for(int i=0;i<b.size();i++)
	{
		int x=b[i].first,y=b[i].second;
		if(book[x]==1&&book[y]!=1) cha[x]=find(y);
		if(book[y]==1&&book[x]!=1) cha[y]=find(x);
	}
	int zhu=cha.begin()->second;
	bool f=1;
	for(auto &i:cha)
	{
		if(zhu!=i.second){f=0;break;}
	}
	if(f==0){cout<<"No";return 0;}
	map <int,set<int>> ans;
	map <int,bool> la;
	for(int i=0;i<a.size();i++)
	{
		int x=a[i].first,y=a[i].second;
		if(x==zhu)
		{
			ans[x].insert(y);
			la[y]=1;
			la[x]=1;
		}
		if(y==zhu)
		{
			ans[y].insert(x);
			la[x]=1;
			la[y]=1;
		}
	}
	for(int i=0;i<a.size();i++)
	{
		int x=a[i].first,y=a[i].second;
		if(book[x]!=1)
		{
			if(la[y]!=1)
			{
				ans[x].insert(y);
				la[y]=1;
				la[x]=1;
			}
		}
		if(book[y]!=1)
		{
			if(la[x]!=1)
			{
				ans[y].insert(x);
				la[x]=1;
				la[y]=1;
			}
		}
	}
	cout<<"Yes"<<'\n';
	cout<<ans.size()<<'\n';
	for(auto it=ans.begin();it!=ans.end();it++)
	{
		cout<<it->first<<' '<<it->second.size();
		for(auto &j:it->second) cout<<' '<<j;
		cout<<'\n';
	}	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5 2
3 4
1 2
1 3
2 3
3 4
2 4

output:

Yes
1
2 3 1 3 4

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 5 3
2 4 3
1 2
1 3
2 3
3 4
2 4

output:

No

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

4 6 2
3 4
1 3
1 4
2 3
2 4
1 2
3 4

output:

Yes
1
2 3 1 3 4

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

6 6 0

1 2
2 3
3 1
4 5
5 6
6 4

output:

No

result:

ok ok

Test #5:

score: -100
Wrong Answer
time: 821ms
memory: 79736kb

input:

200000 199999 2
142330 49798
49798 116486
116486 64386
64386 192793
192793 61212
61212 138489
138489 83788
83788 89573
89573 8596
8596 156548
156548 41800
41800 14478
14478 27908
27908 82806
82806 9353
9353 160166
160166 92308
92308 36265
36265 126943
126943 190578
190578 191148
191148 177381
177381...

output:

Yes
199996
1 1 178679
2 1 198122
3 1 41738
4 1 61178
5 1 91673
6 1 151278
7 1 136018
8 1 100182
9 1 101606
10 1 160835
11 1 105951
12 1 169521
13 1 130553
14 1 147118
15 1 196567
16 1 50682
17 1 72182
18 1 141202
19 1 45379
20 1 130909
21 1 147232
22 1 114131
23 1 40268
24 1 50553
25 1 163991
26 1 1...

result:

wrong answer on step #2, member 2 is not invited before inviting others