QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640913#9453. Graph Generatorhaze#AC ✓517ms10016kbC++231.9kb2024-10-14 16:51:252024-10-14 16:51:26

Judging History

你现在查看的是测评时间为 2024-10-14 16:51:26 的历史记录

  • [2024-10-14 16:54:59]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:502ms
  • 内存:9980kb
  • [2024-10-14 16:52:42]
  • hack成功,自动添加数据
  • (/hack/991)
  • [2024-10-14 16:51:26]
  • 评测
  • 测评结果:100
  • 用时:517ms
  • 内存:10016kb
  • [2024-10-14 16:51:25]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define irep(i,l,r) for(ll i = l; i <= r; ++ i)
typedef long long ll;
#define IOS ios::sync_with_stdio(false),cin.tie(0);

const int N = 200000 + 7;

void solve(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>>g(n);
	vector<int>deg(n);
	set<array<int, 2>>st;
	irep(i, 0, m - 1){
		int x, y;
		cin >> x >> y;
		-- x, -- y;
		g[x].push_back(y);
		g[y].push_back(x);
		deg[x] ++, deg[y] ++;
	}

	irep(x, 0, n - 1){
		st.insert({deg[x], (int)x});
	}

	vector<int>q;
	while(st.size()){
		auto [DD, idx] = *st.rbegin();
		deg[idx] = -1;
		st.erase(*st.rbegin());
		q.push_back(idx);
		for(int y : g[idx]){
			st.extract({deg[y], y});
			deg[y] --;
			if(deg[y] >= 0)st.insert({deg[y], y});
		}
	}
	reverse(q.begin(), q.end());
	vector<vector<int>>ans(n);
	vector<int>fa(n), sz(n), getp(n);
	irep(i, 0, n - 1){
		fa[i] = i, sz[i] = 1;
//        cerr << q[i] + 1 << ' ';
	}
	function<int(int)>find = [&](int x){
		if(fa[x] == x)return fa[x];
		fa[x] = find(fa[x]);
		return fa[x];
	};
	auto merge = [&](int x, int y){
		x = find(x), y = find(y);
		if(sz[x] > sz[y])swap(x, y);
		sz[y] += sz[x];
		fa[x] = y;
	};
	irep(i, 0, n - 1){
		getp[q[i]] = i;
	}
	irep(i, 0, n - 1){
//        cerr << endl << i << endl;
		int x = q[i];
		map<int, int>ff;
		for(int y : g[x]){
			if(getp[y] > getp[x])continue;
			ff[find(y)] ++;
            if(ff[find(y)] == 1)
    			ans[i].push_back(y);
		}
		for(int y : ans[i]){
			if(sz[find(y)] != ff[find(y)]){
				cout << "No\n";
				return;
			}
        }
        for(int y : ans[i]){
            merge(x, y);
        }
	}
	cout << "Yes\n";
//    return;
	irep(i, 0, n - 1){
		cout << q[i] + 1 << ' ' << ans[i].size();
		for(int pp : ans[i])cout << ' ' << pp + 1;
		cout << '\n';
	}
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 517ms
memory: 10016kb

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

result:

ok 4176 cases passed

Extra Test:

score: 0
Extra Test Passed