QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790923#9525. Welcome to Join the Online Meeting!YehhhhTL 0ms3776kbC++201.7kb2024-11-28 16:02:562024-11-28 16:03:03

Judging History

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

  • [2024-11-28 16:03:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3776kb
  • [2024-11-28 16:02:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

vector<int> ans;

void dfs(int now, vector<vector<int>> f, vector<int> nofree, vector<int>& inn, int& person, vector<vector<int>>& st) {
    for (auto x : f[now]) {
        if (inn[x] == 0) {
            inn[x] = 1;
            person++;
            st[now].push_back(x);
            if (nofree[x] == 0 && f[x].size() > 1) {
                dfs(x, f, nofree, inn, person, st);
            }
        }
    }
    if (st[now].size() != 0) {
        ans.push_back(now);
    }
}

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> nofree(n + 1);
    for (int i = 0; i < k; i++) {
        int x;
        cin >> x;
        nofree[x] = 1;
    }
    vector<vector<int>> f(n + 1);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        if (nofree[x] == 0) {
            f[x].push_back(y);
        }
        if (nofree[y] == 0) {
            f[y].push_back(x);
        }
    }
    vector<vector<int>> st(n + 1);
    vector<int> inn(n + 1);
    int person = 1;
    for (int i = 1; i <= n; i++) {
        if (nofree[i] == 0) {
            inn[i] = 1;
            dfs(i, f, nofree, inn, person, st);
            break;
        }
    }
    if (person != n) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    cout << ans.size() << "\n";
    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << " " << st[ans[i]].size();
        for (auto x : st[ans[i]]) {
            cout << " " << x;
        }
        cout << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

Yes
2
1 1 2
2 2 3 4

result:

ok ok

Test #2:

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

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

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: 0ms
memory: 3548kb

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
Time Limit Exceeded

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:


result: