QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634633#9453. Graph Generatorucup-team4717#TL 955ms43928kbC++202.3kb2024-10-12 17:46:532024-10-12 17:46:53

Judging History

你现在查看的是测评时间为 2024-10-12 17:46:53 的历史记录

  • [2024-10-14 16:53:54]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:TL
  • 用时:996ms
  • 内存:41648kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-12 17:46:53]
  • 评测
  • 测评结果:100
  • 用时:955ms
  • 内存:43928kb
  • [2024-10-12 17:46:53]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define sd second
using namespace std;
const int N=2e5+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48,ch=getchar();}
	return x*f;
}
int T,n,m,tot,in[N];
set<int> e[N];
set<pii,greater<pii > > s;
bool flg;

int vis[N],idx,siz,mx;
void dfs(int u){
	vis[u]=idx,siz++;
	for(int v:e[u]){
		if(vis[v]!=idx){
			dfs(v);
			if(siz-1>mx) return;
		}
	}
}
void dfs2(int u){
	vis[u]=idx;
	for(int v:e[u])
		if(vis[v]!=idx) 
			dfs2(v);
}

int id[N];
vector<int> ans[N];

int fa[N],sz[N],U[N],V[N],In[N];
inline int Find(int x){
	return x==fa[x]?x:fa[x]=Find(fa[x]);
}

map<int,int> mp;
map<pair<int,int> ,bool> lk;

inline void merge(int x,int y){
	x=Find(x),y=Find(y);
	if(x==y) return;
	fa[x]=y,sz[y]+=sz[x];
}

signed main(){	
	T=read();
	while(T--){
		n=read(),m=read(),flg=0;
		for(int u,v,i=1;i<=m;i++){
			u=read(),v=read();
			e[u].insert(v);
			e[v].insert(u);
			U[i]=u,V[i]=v;
			in[u]++,in[v]++;
		}
		idx=1,tot=0,s.clear();
		for(int i=1;i<=n;i++) s.insert({in[i],i});
		while(!s.empty()){
			int u=(*s.begin()).sd;
			s.erase(s.begin());

			for(int v:e[u]){
				s.erase({in[v],v});
				in[v]--;
				s.insert({in[v],v});
				e[v].erase(u);
			}			

			for(int v:e[u])
				ans[u].emplace_back(v);
			
			id[++tot]=u;
		}
		lk.clear();
		for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
		for(int i=tot;i;i--){
			int f=id[i];
			mp.clear();
			vector<int> real;
			int sum=0;
			for(int x:ans[f]){
				lk[{x,f}]=1;
				if(!mp[Find(x)]) mp[Find(x)]=1,real.emplace_back(x),sum+=sz[Find(x)];
			}
			if(sum!=in[f]){
				flg=1;
				break;
			}
			ans[f]=real;
			for(int x:ans[f]) merge(x,f);
		}
		if(lk.size()!=m) flg=1;
		if(!flg){
			for(int i=1;i<=m;i++){
				if(!lk[{U[i],V[i]}]&&!lk[{V[i],U[i]}]){
					flg=1;
					break;
				}
			}			
		}

		if(flg){
			puts("No");
			for(int i=1;i<=n;i++) vis[i]=0,in[i]=0,e[i].clear(),ans[i].clear();
			continue;
		}
		puts("Yes");
		for(int i=tot;i;i--){
			int f=id[i];
			printf("%d ",f);
			printf("%d ",(int)ans[f].size());
			for(int x:ans[f]) printf("%d ",x);
			puts("");
		}
		for(int i=1;i<=n;i++) vis[i]=0,in[i]=0,e[i].clear(),ans[i].clear();
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 3 
No

result:

ok 3 cases passed

Test #2:

score: 0
Accepted
time: 955ms
memory: 43928kb

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

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed