QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634562#9453. Graph Generatorucup-team3661#AC ✓159ms10460kbC++201.4kb2024-10-12 17:36:382024-10-14 16:53:54

Judging History

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

  • [2024-10-14 16:53:54]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:159ms
  • 内存:10460kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-12 17:36:39]
  • 评测
  • 测评结果:100
  • 用时:177ms
  • 内存:10476kb
  • [2024-10-12 17:36:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;


void solve(){
	int N,M;cin>>N>>M;
	vector<int>D(N);
	vector<pair<int,int>>E(M);
	for(auto&[u,v]:E){
		cin>>u>>v;
		u--;
		v--;
		D[u]++;
		D[v]++;
	}
	vector<int>idx(N);
	iota(idx.begin(),idx.end(),0);
	sort(idx.begin(),idx.end(),[&](int a,int b){
		if(D[a]!=D[b])return D[a]<D[b];
		return a<b;
	});
	vector<vector<int>>G(N);
	for(auto[u,v]:E){
		if(D[u]>D[v]||(D[u]==D[v]&&u>v))swap(u,v);
		G[v].push_back(u);
	}

	vector<int>par(N),sz(N);
	for(int i=0;i<N;i++){
		par[i]=i;
		sz[i]=1;
	}
	auto find=[&](auto&&find,int x)->int{
		if(par[x]==x)return x;
		return par[x]=find(find,par[x]);
	};
	auto merge=[&](int x,int y)->void{
		x=find(find,x);
		y=find(find,y);
		if(x==y)return;
		if(sz[x]<sz[y])swap(x,y);
		sz[x]+=sz[y];
		par[y]=x;
	};

	vector<pair<int,vector<int>>>ans;
	for(int i:idx){
		vector<int>me;
		for(int nxt:G[i])me.push_back(find(find,nxt));
		for(int nxt:G[i])merge(i,nxt);
		if(sz[find(find,i)]-1!=G[i].size()){
			cout<<"No\n";
			return;
		}
		sort(me.begin(),me.end());
		me.erase(unique(me.begin(),me.end()),me.end());
		ans.push_back({i,me});
	}

	cout<<"Yes\n";
	for(auto[x,v]:ans){
		cout<<x+1<<' ';
		cout<<v.size()<<' ';
		for(int y:v)cout<<y+1<<' ';
		cout<<'\n';
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;cin>>T;
	while(T--){
		solve();
	}
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

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

output:

Yes
1 0 
2 0 
3 0 
Yes
1 0 
3 0 
4 1 3 
2 2 1 4 
No

result:

ok 3 cases passed

Test #2:

score: 0
Accepted
time: 159ms
memory: 10460kb

input:

4176
10 15
1 4
9 1
3 7
8 1
2 1
5 4
5 1
10 1
7 1
10 7
10 3
6 4
3 1
6 1
9 2
7 10
6 7
1 7
1 4
7 2
4 2
5 2
3 1
1 6
2 6
5 1
6 8
5 2
3 1
4 6
2 1
5 1
1 4
6 2
6 1
9 15
5 1
4 2
7 1
1 8
2 3
5 8
1 9
4 3
6 5
9 2
3 1
4 1
7 2
9 7
1 6
6 11
1 2
3 5
3 1
3 2
4 3
1 6
4 2
1 4
5 4
5 1
5 2
6 6
1 6
6 3
1 3
1 5
4 2
2 1
10 ...

output:

Yes
8 0 
2 0 
5 0 
6 0 
9 1 2 
3 0 
4 2 5 6 
7 1 3 
10 1 7 
1 4 4 7 8 9 
No
No
No
Yes
6 0 
2 0 
3 1 2 
4 1 3 
5 1 3 
1 2 3 6 
No
No
Yes
2 0 
3 0 
7 1 3 
4 0 
5 1 4 
6 1 5 
1 3 2 5 7 
Yes
4 0 
5 0 
7 0 
8 0 
9 0 
6 0 
10 0 
3 2 6 10 
2 5 3 5 7 8 9 
1 2 3 4 
Yes
9 0 
4 0 
6 0 
7 0 
8 0 
5 2 7 8 
2 2 5...

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed