QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771914#9453. Graph GeneratorqwqUwU_AC ✓86ms18384kbC++141.6kb2024-11-22 16:17:202024-11-22 16:17:20

Judging History

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

  • [2024-11-22 16:17:20]
  • 评测
  • 测评结果:AC
  • 用时:86ms
  • 内存:18384kb
  • [2024-11-22 16:17:20]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll; 
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline ll read(){
	ll x=0,f=1,c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
const int N=1e5+3;
int n,m,fa[N],p[N],cnt[N],vis[N];
vector<int>G[N];
inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
vector<int>vec[N];
inline void solve(){
	n=read(),m=read();
	rep(i,1,n)G[i].clear(),vec[i].clear(),fa[i]=0,p[i]=i,cnt[i]=vis[i]=0;
	rep(i,1,m){
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
	}
	sort(p+1,p+n+1,[&](int i,int j){return G[i].size()<G[j].size();});
	rep(I,1,n){
		int i=p[I];fa[i]=i,cnt[i]=1;
		for(int j:G[i])if(fa[j]){
			int v=find(j);vec[i].pb(v);
			++vis[v];
		}
		bool fl=1;
		sort(vec[i].begin(),vec[i].end());
		vec[i].erase(unique(vec[i].begin(),vec[i].end()),vec[i].end());
		for(int v:vec[i]){
			if(vis[v]!=cnt[v]){fl=0;break;}
			vis[v]=0;
		}
		if(!fl){
			puts("No");
			return ;
		}
		for(int v:vec[i])fa[v]=i,cnt[i]+=cnt[v];
	}
	puts("Yes");
	rep(I,1,n){
		int i=p[I];
		printf("%d %d ",i,vec[i].size());
		for(int x:vec[i])printf("%d ",x);
		puts("");
	}
}
int main() {
    //freopen("data.in", "r", stdin);
    // freopen("myans.out","w",stdout);
	int T=read();while(T--)solve();
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 86ms
memory: 18384kb

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 8 9 10 
No
No
No
Yes
6 0 
2 0 
3 1 2 
4 1 3 
5 1 4 
1 2 5 6 
No
No
Yes
2 0 
3 0 
7 1 3 
4 0 
5 1 4 
6 1 5 
1 3 2 6 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 2 4 
Yes
9 0 
4 0 
6 0 
7 0 
8 0 
5 2 7 8 
2 2 ...

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed