168582025-05-14 10:34:32AblablablaPletykacpp17Időlimit túllépés 88/100178ms15408 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++;
    }

    ans.push_back(db[t % 2] + egy);

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

    t++;
    egy = 0;

    cout << maxi << "\n" << hely << "\n";
    for(int i = 0; i < hely; i++){
        cout << ans[i] << " ";
    }
    cout << "\n";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base88/100
1Elfogadva0/01ms508 KiB
2Elfogadva0/032ms4364 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/22ms564 KiB
5Elfogadva2/22ms644 KiB
6Elfogadva2/24ms1168 KiB
7Elfogadva4/44ms1188 KiB
8Elfogadva4/48ms1788 KiB
9Elfogadva4/48ms1708 KiB
10Elfogadva4/48ms1740 KiB
11Elfogadva4/429ms4276 KiB
12Elfogadva4/426ms4364 KiB
13Elfogadva4/439ms6344 KiB
14Elfogadva4/452ms7056 KiB
15Elfogadva6/668ms9388 KiB
16Elfogadva6/672ms9380 KiB
17Elfogadva6/6108ms12420 KiB
18Elfogadva6/698ms12456 KiB
19Elfogadva6/687ms12460 KiB
20Elfogadva6/6116ms13480 KiB
21Elfogadva6/6119ms13484 KiB
22Elfogadva6/6115ms13476 KiB
23Időlimit túllépés0/6163ms15408 KiB
24Időlimit túllépés0/6178ms15408 KiB