QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715089#9525. Welcome to Join the Online Meeting!retired_midlightsWA 38ms15676kbC++142.1kb2024-11-06 10:23:242024-11-06 10:23:25

Judging History

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

  • [2024-11-06 10:23:25]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:15676kb
  • [2024-11-06 10:23:24]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i <= (int)b; i ++)
#define per(i, a, b) for(int i = (int)a; i >= (int)b; i --)
#define ll long long
#define no { puts("No"); return; }
#define yes { puts("Yes"); return; }
using namespace std;
const int maxn = 200010;
int n, m, k, f[maxn];
bool ins[maxn], busy[maxn];
vector < vector < int > > res;
vector < int > e[maxn];
int find(int x) { return f[x] == x ? f[x] : f[x] = find(f[x]); }
void dfs(int u, int fa) {
    vector < int > cur;
    cur.push_back(u);
    for(auto v : e[u]) if(v != fa && !ins[v]) {
        cur.push_back(v);
        ins[v] = 1;
    }
    if(cur.size() == 1) return;
    res.push_back(cur);
    for(int i = 1; i < cur.size(); i ++)
        if(!busy[cur[i]]) dfs(cur[i], u);
}
void solve() {
    cin >> n >> m >> k;
    rep(i, 1, n) f[i] = i, ins[i] = busy[i] = 0, e[i].clear();
    rep(i, 1, k) {
        int x;
        cin >> x;
        busy[x] = 1;
    }
    rep(i, 1, m) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v), e[v].push_back(u);
        if(!busy[u] && !busy[v]) {
            int r1 = find(u), r2 = find(v);
            if(r1 == r2) continue;
            f[r1] = r2;
        } else if(!(busy[u] && busy[v])) {
            if(busy[u]) ins[u] = 1;
            else ins[v] = 1;
        }
    }
    int id = -1;
    rep(i, 1, n) if(f[i] == i && !busy[i]) { id = i; break; }
    if(id == -1) {
        cout << "No\n";
        return;
    }
    rep(i, 1, n) if((!busy[i] && f[i] != id) || (busy[i] && !ins[i])) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    rep(i, 1, n) ins[i] = 0;
    res.clear();
    dfs(id, 0);
    cout << res.size() << '\n';
    for(auto a : res) {
        cout << a[0] << ' ' << a.size() - 1;
        rep(i, 1, a.size() - 1) cout << ' ' << a[i];
        cout << '\n';
    }
}

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
#endif
    ios :: sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    while(T --) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 8272kb

input:

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

output:

Yes
1
2 3 1 3 4

result:

ok ok

Test #2:

score: 0
Accepted
time: 2ms
memory: 8660kb

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: 8196kb

input:

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

output:

Yes
1
2 3 3 4 1

result:

ok ok

Test #4:

score: 0
Accepted
time: 2ms
memory: 8472kb

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: 38ms
memory: 15676kb

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