168612025-05-14 10:44:42AblablablaPletykacpp17Time limit exceeded 82/100171ms15408 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

vector<vector<int>> csucsok, ido;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m, k;
    cin >> n >> m >> k;

    vector<int> kezd(k);
    for(int &x : kezd){
        cin >> x;
        x--;
    }

    csucsok.assign(n, vector<int>());
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;

        csucsok[a].push_back(b);
        csucsok[b].push_back(a);
    }

    ido.assign(n, vector<int>(2, -1)); // 0-paros, 1-paratlan

    queue<pii> bejar;
    for(int x : kezd){
        bejar.push({x, 1});
    }

    while(!bejar.empty()){
        auto [akt, t] = bejar.front();
        bejar.pop();

        if(ido[akt][t % 2] != -1) continue;

        ido[akt][t % 2] = t;
        t++;

        for(int x : csucsok[akt]){
            if(ido[x][t % 2] != -1) continue;

            bejar.push({x, t});
        }
    }

    int ps = 0, pt = 0;
    for(int i = 0; i < n; i++){
        if(csucsok[i].size() == 0) continue;

        if(ido[i][0] != -1){
            ps++;
        }
        if(ido[i][1] != -1){
            pt++;
        }
    }

    int maxi = max(k, max(ps, pt));

    vector<pii> poz;
    for(int i = 0; i < n; i++){
        if(ido[i][0] != -1){
            poz.push_back({ido[i][0], i});
        }

        if(ido[i][1] != -1){
            poz.push_back({ido[i][1], i});
        }
    }

    sort(poz.begin(), poz.end());

    int t = 1;
    int ind = 0;
    vector<int> db(2, 0);
    int egy = 0;
    vector<int> ans;

    while(ind < poz.size()){
        if(poz[ind].first > t){
            ans.push_back(db[t % 2] + egy);

            if(ans.back() == maxi) break;

            t++;
            egy = 0;

            while(t < poz[ind].first){
                ans.push_back(db[t % 2]);

                if(ans.back() == maxi) break;

                t++;
            }
        }

        if(csucsok[poz[ind].second].size() == 0){
            egy++;
        } else{
            db[t % 2]++;
        }

        ind++;
    }

    if(ans.back() != maxi){
        ans.push_back(db[t % 2] + egy);
        t++;
        egy = 0;
    }

    cout << maxi << "\n" << ans.size() << "\n";
    for(int x : ans){
        cout << x << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base82/100
1Accepted0/01ms316 KiB
2Accepted0/028ms4232 KiB
3Accepted2/21ms316 KiB
4Accepted2/22ms564 KiB
5Accepted2/23ms708 KiB
6Accepted2/24ms1076 KiB
7Accepted4/44ms1156 KiB
8Accepted4/48ms1784 KiB
9Accepted4/48ms1596 KiB
10Accepted4/47ms1588 KiB
11Accepted4/429ms4316 KiB
12Accepted4/427ms4220 KiB
13Accepted4/439ms6548 KiB
14Accepted4/446ms6924 KiB
15Accepted6/675ms9388 KiB
16Accepted6/667ms9392 KiB
17Accepted6/689ms12324 KiB
18Accepted6/6111ms12456 KiB
19Accepted6/6101ms12460 KiB
20Accepted6/6101ms13376 KiB
21Accepted6/6101ms13404 KiB
22Time limit exceeded0/6130ms13480 KiB
23Time limit exceeded0/6171ms15408 KiB
24Time limit exceeded0/6158ms15408 KiB