100662024-03-25 21:51:47szilPletykacpp17Accepted 100/10094ms20032 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 100'001;

int cnt[MAXN], vis[MAXN];
bool vis2[MAXN];
vector<int> g[MAXN];

void solve() {
    int n, m, k; cin >> n >> m >> k;
    fill(vis, vis+MAXN, -1);
    queue<int> q, q2;
    for (int i = 1; i <= k; i++) {
        int x; cin >> x;
        vis[x] = 0;
        q.push(x);
    }
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    q.push(-1);
    q2.push(-1);
    int day = 0;
    while (q.size() > 1 || q2.size() > 1) {
        vector<int> now;
        while (q.front() != -1) {
            int u = q.front(); q.pop();
            now.emplace_back(u);
        }

        q.pop();
        for (int u : now) {
            if (day == 0 && g[u].empty()) {
                cnt[2]--;
            }
            for (int v : g[u]) {
                if (vis[v] == -1) {
                    q.push(v);
                    vis[v] = day + 1;
                }
                else if (vis[v] == day && !vis2[v]) {
                    q2.push(v);
                    vis2[v] = true;
                }
            }
        }
        q.push(-1);
        cnt[day] += now.size();

        while (q2.front() != -1) {
            int u = q2.front(); q2.pop();
            cnt[day]++;
            for (int v : g[u]) {
                if (!vis2[v]) {
                    q2.push(v);
                    vis2[v] = true;
                }
            }
        }

        q2.pop();
        q2.push(-1);

        day++;
    }
    pair<int, int> ans = {0, 0};
    vector<int> res;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, {cnt[i], -i});
        res.emplace_back(cnt[i]);
        cnt[i+2] += cnt[i];
    }
    cout << ans.first << "\n" << -ans.second+1 << "\n";
    for (int i = 0; i <= -ans.second; i++) {
        cout << res[i] << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/04ms7392 KiB
2Accepted0/020ms10204 KiB
3Accepted2/24ms7800 KiB
4Accepted2/24ms7928 KiB
5Accepted2/24ms8228 KiB
6Accepted2/27ms8580 KiB
7Accepted4/46ms8540 KiB
8Accepted4/48ms9032 KiB
9Accepted4/48ms9032 KiB
10Accepted4/48ms9036 KiB
11Accepted4/419ms10800 KiB
12Accepted4/418ms10780 KiB
13Accepted4/428ms12596 KiB
14Accepted4/430ms12716 KiB
15Accepted6/641ms14820 KiB
16Accepted6/641ms14784 KiB
17Accepted6/652ms16360 KiB
18Accepted6/652ms16340 KiB
19Accepted6/654ms17260 KiB
20Accepted6/656ms17244 KiB
21Accepted6/654ms17260 KiB
22Accepted6/659ms17268 KiB
23Accepted6/694ms19960 KiB
24Accepted6/694ms20032 KiB