100662024-03-25 21:51:47szilPletykacpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/04ms7392 KiB
2Elfogadva0/020ms10204 KiB
3Elfogadva2/24ms7800 KiB
4Elfogadva2/24ms7928 KiB
5Elfogadva2/24ms8228 KiB
6Elfogadva2/27ms8580 KiB
7Elfogadva4/46ms8540 KiB
8Elfogadva4/48ms9032 KiB
9Elfogadva4/48ms9032 KiB
10Elfogadva4/48ms9036 KiB
11Elfogadva4/419ms10800 KiB
12Elfogadva4/418ms10780 KiB
13Elfogadva4/428ms12596 KiB
14Elfogadva4/430ms12716 KiB
15Elfogadva6/641ms14820 KiB
16Elfogadva6/641ms14784 KiB
17Elfogadva6/652ms16360 KiB
18Elfogadva6/652ms16340 KiB
19Elfogadva6/654ms17260 KiB
20Elfogadva6/656ms17244 KiB
21Elfogadva6/654ms17260 KiB
22Elfogadva6/659ms17268 KiB
23Elfogadva6/694ms19960 KiB
24Elfogadva6/694ms20032 KiB