QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633148#9453. Graph Generatorucup-team4938#AC ✓451ms31940kbC++141.5kb2024-10-12 14:39:022024-10-12 14:39:07

Judging History

你现在查看的是测评时间为 2024-10-12 14:39:07 的历史记录

  • [2024-10-14 16:53:11]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:457ms
  • 内存:30504kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-12 14:39:07]
  • 评测
  • 测评结果:100
  • 用时:451ms
  • 内存:31940kb
  • [2024-10-12 14:39:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n, m, a[100010][2], b[100010], c[100010], deg[100010], hd[100010], e[200010][2], fa[100010], siz[100010];
vector<int> ans[100010], T[100010];
set<int> S[100010];
bool cmp(int x, int y){ return deg[x] > deg[y]; }
void solve(){
	int i, j, u, v, x = 0;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++) deg[i] = 0, hd[i] = 0, b[i] = i, siz[i] = 1, ans[i].clear(), S[i].clear(), T[i].clear();
	for(i = 1; i <= n; i++) T[i].push_back(i);
	for(i = 1, j = 1; i <= m; i++, j++){
		scanf("%d%d", &u, &v); deg[u]++; deg[v]++;
		e[j][0] = hd[u]; e[j][1] = v; hd[u] = j;
		j++;
		e[j][0] = hd[v]; e[j][1] = u; hd[v] = j;
		S[u].insert(v); S[v].insert(u);
	}
	sort(b + 1, b + n + 1, cmp);
	for(i = 1; i <= n; i++) c[b[i]] = i;
	for(u = 1; u <= n; u++){
		fa[u] = 0;
		for(i = hd[u]; i > 0; i = e[i][0]){
			v = e[i][1];
			if(c[v] < c[u] && (fa[u] == 0 || c[v] > c[fa[u]])) fa[u] = v;
		}
		if(fa[u] > 0) ans[fa[u]].push_back(u);
	}
	for(i = n; i >= 1; i--){
		u = b[i];
		x += siz[u] - 1;
		if(fa[u] > 0){
			siz[fa[u]] += siz[u];
			for(j = 0; j < T[u].size(); j++){
				if(!S[fa[u]].count(T[u][j])){ printf("No\n"); return; }
				T[fa[u]].push_back(T[u][j]);
			}
		}
	}
	if(x < m){ printf("No\n"); return; }
	printf("Yes\n");
	for(i = n; i >= 1; i--){
		printf("%d %d ", b[i], ans[b[i]].size());
		for(j = 0; j < ans[b[i]].size(); j++) printf("%d ", ans[b[i]][j]);
		printf("\n");
	}
}
int main()
{
	int t;
	scanf("%d", &t);
	while(t--) solve();
	return 0;
}

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

详细

Test #1:

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

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
3 0 
2 0 
1 0 
Yes
1 0 
4 0 
3 1 4 
2 2 1 3 
No

result:

ok 3 cases passed

Test #2:

score: 0
Accepted
time: 451ms
memory: 31940kb

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

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed