168562025-05-14 10:32:08AblablablaPletykacpp17Wrong answer 44/100188ms13584 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

vector<vector<int>> csucsok, ido;

int main(){
    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
base44/100
1Accepted0/01ms316 KiB
2Accepted0/045ms4268 KiB
3Accepted2/21ms316 KiB
4Accepted2/22ms316 KiB
5Accepted2/23ms688 KiB
6Accepted2/27ms1092 KiB
7Accepted4/47ms1036 KiB
8Wrong answer0/413ms1692 KiB
9Accepted4/412ms1716 KiB
10Wrong answer0/412ms1652 KiB
11Accepted4/443ms4284 KiB
12Accepted4/439ms4236 KiB
13Accepted4/463ms6324 KiB
14Accepted4/471ms6832 KiB
15Accepted6/6111ms9384 KiB
16Accepted6/6108ms9384 KiB
17Time limit exceeded0/6128ms12464 KiB
18Time limit exceeded0/6140ms12460 KiB
19Time limit exceeded0/6128ms12452 KiB
20Time limit exceeded0/6166ms13480 KiB
21Time limit exceeded0/6167ms13480 KiB
22Time limit exceeded0/6185ms13584 KiB
23Time limit exceeded0/6188ms12340 KiB
24Time limit exceeded0/6180ms12272 KiB