QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729538#9525. Welcome to Join the Online Meeting!DBsoleil#WA 2ms12012kbC++231.6kb2024-11-09 17:18:482024-11-09 17:19:04

Judging History

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

  • [2024-11-09 17:19:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12012kb
  • [2024-11-09 17:18:48]
  • 提交

answer


#include <bits/stdc++.h>
using namespace std;
static constexpr int Maxn = 2e5 + 5, Maxm = 5e5 + 5;
int n, m, k, ck;
int a[Maxn], bad[Maxn], fa[Maxn], eu[Maxm], ev[Maxm], vis[Maxn];
vector<int> g[Maxn];
int fnd(int x) { return x == fa[x] ? x : fa[x] = fnd(fa[x]); }
void join(int x, int y) { x = fnd(x), y = fnd(y); if (x != y) fa[x] = y; }
void add_edge(int u, int v) { g[u].push_back(v), g[v].push_back(u); }
vector<pair<int, vector<int>>> ans;
int main(void) {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n >> m >> k;
  if (k == n) { cout << "No\n"; return 0; }
  for (int i = 1; i <= k; ++i) cin >> a[i], bad[a[i]] = true;
  for (int i = 1; i <= m; ++i) cin >> eu[i] >> ev[i], add_edge(eu[i], ev[i]);
  for (int i = 1; i <= n; ++i) fa[i] = i; ck = 0;
  for (int i = 1; i <= m; ++i)
    if (!bad[eu[i]] && !bad[ev[i]]) join(eu[i], ev[i]);
  for (int i = 1; i <= n; ++i) ck += (fa[i] == i);
  if (ck != k + 1) { cout << "No\n"; return 0; }
  for (int i = 1; i <= k; ++i) {
    int cv = 0; for (int v: g[a[i]]) cv += !bad[v];
    if (cv == 0) { cout << "No\n"; return 0; }
  } queue<int> que;
  for (int i = 1; i <= n; ++i) if (!bad[i])
  { que.push(i); vis[i] = true; break; }
  while (!que.empty()) {
    int u = que.front(); que.pop();
    if (bad[u]) continue;
    vector<int> cur;
    for (int v: g[u]) if (!vis[v])
      cur.push_back(v), que.push(v), vis[v] = true;
    ans.emplace_back(u, cur);
  } cout << "Yes\n";
  cout << (int)ans.size() << endl;
  for (const auto &[x, y]: ans) {
    cout << x << ' ' << (int)y.size();
    for (const int &z: y) cout << ' ' << z; cout << endl;
  } return 0;
} // main

詳細信息

Test #1:

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

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: 2ms
memory: 9956kb

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: -100
Wrong Answer
time: 0ms
memory: 9764kb

input:

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

output:

Yes
2
1 3 3 4 2
2 0

result:

wrong answer Integer parameter [name=y_j] equals to 0, violates the range [1, 4]