168572025-05-14 10:33:00AblablablaPletykacpp17Wrong answer 56/100173ms15408 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});
        }
    }

    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;
    int maxi = 0;
    int hely = 0;

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

            if(ans.back() > maxi){
                maxi = ans.back();
                hely = t;
            }

            t++;
            egy = 0;

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

                if(ans.back() > maxi){
                    maxi = ans.back();
                    hely = t;
                }

                t++;
            }
        }

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

        ind++;
    }

    cout << maxi << "\n" << hely << "\n";
    for(int i = 0; i < hely; i++){
        cout << ans[i] << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base56/100
1Accepted0/01ms508 KiB
2Accepted0/028ms4276 KiB
3Accepted2/21ms512 KiB
4Accepted2/22ms564 KiB
5Accepted2/23ms664 KiB
6Accepted2/24ms1076 KiB
7Accepted4/44ms1040 KiB
8Wrong answer0/48ms1608 KiB
9Accepted4/48ms1732 KiB
10Wrong answer0/48ms1644 KiB
11Accepted4/429ms4324 KiB
12Accepted4/426ms4276 KiB
13Accepted4/437ms6448 KiB
14Accepted4/450ms7056 KiB
15Accepted6/676ms9392 KiB
16Accepted6/667ms9552 KiB
17Wrong answer0/687ms12456 KiB
18Wrong answer0/6114ms12456 KiB
19Accepted6/687ms12460 KiB
20Accepted6/6101ms13460 KiB
21Wrong answer0/6109ms13480 KiB
22Time limit exceeded0/6131ms13520 KiB
23Time limit exceeded0/6173ms15408 KiB
24Time limit exceeded0/6173ms15324 KiB