QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768678#9525. Welcome to Join the Online Meeting!wk6_WA 124ms67200kbC++171.7kb2024-11-21 13:36:482024-11-21 13:36:49

Judging History

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

  • [2024-11-21 13:36:49]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:67200kb
  • [2024-11-21 13:36:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f3f3f3f3f
#define PII pair<int, int>
const int N = 2e6 + 10;
int n, m, k, pr[N], a[N];
int find(int x) {
	if (pr[x] == x)return x;
	return pr[x] = find(pr[x]);
}
void join(int x, int y) {
	int fx = find(x), fy = find(y);
	if (fx != fy) {
		pr[fx] = fy;
	}
}
vector<int>g[N];
void solve() {
	cin >> n >> m >> k;
	map<int, int>mp;
	for (int i = 1; i <= n; i++)pr[i] = i;
	for (int i = 1; i <= k; i++) {
		cin >> a[i];
		mp[a[i]] = 1;
	}
	set<int>ans;
	int fa = 0;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;

		if (find(u) != find(v)) {
			if (mp[u] == 0) {
				if (ans.size() == 0) {
					join(v, u);
					ans.insert(u);
					g[u].push_back(v);
					fa = u;
				} else {
					if (find(u) == fa) {
						join(v, u);
						ans.insert(u);
						g[u].push_back(v);
						fa = u;
					}
				}
			} else if (mp[v] == 0) {
				if (ans.size() == 0) {
					join(u, v);
					ans.insert(v);
					g[v].push_back(u);
					fa = v;
				} else {
					if (find(v) == fa) {
						join(u, v);
						ans.insert(v);
						g[v].push_back(u);
						fa = v;
					}
				}
			}
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (pr[i] == i)cnt++;
	}
	if (cnt != 1)cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		cout << ans.size() << endl;
		for (auto t : ans) {
			cout << t << " ";
			cout << g[t].size() << " ";
			for (int j = 0; j < g[t].size(); j++) {
				cout << g[t][j] << " ";
			}
			cout << endl;
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int _ = 1;
//	cin >> _;
	while (_--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 54272kb

input:

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

output:

Yes
2
1 2 2 3 
2 1 4 

result:

ok ok

Test #2:

score: 0
Accepted
time: 3ms
memory: 52532kb

input:

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

output:

No

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 52888kb

input:

4 6 2
3 4
1 3
1 4
2 3
2 4
1 2
3 4

output:

Yes
1
1 3 3 4 2 

result:

ok ok

Test #4:

score: 0
Accepted
time: 5ms
memory: 54176kb

input:

6 6 0

1 2
2 3
3 1
4 5
5 6
6 4

output:

No

result:

ok ok

Test #5:

score: -100
Wrong Answer
time: 124ms
memory: 67200kb

input:

200000 199999 2
142330 49798
49798 116486
116486 64386
64386 192793
192793 61212
61212 138489
138489 83788
83788 89573
89573 8596
8596 156548
156548 41800
41800 14478
14478 27908
27908 82806
82806 9353
9353 160166
160166 92308
92308 36265
36265 126943
126943 190578
190578 191148
191148 177381
177381...

output:

No

result:

wrong answer jury has found a solution, but participant hasn't