12172022-03-25 20:04:58Szin AttilaPletykacpp14Time limit exceeded 88/100136ms54152 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const ll maxN = 2e5 + 5;
const ll MOD = 1e9 + 7;

inline int read(){
    int res=0; char ch=getchar();
    while(ch < '0' || '9' < ch) ch=getchar();
    while('0' <= ch && ch <= '9'){
        res=(res<<3) + (res<<1)+ch-'0';
        ch=getchar();
    }
    return res;
}


int main() {
    /*freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);*/
   InTheNameOfGod;
    
    ll n,m,k;
    n = read(); m = read(); k = read();

    vector<vector<ll> > g(n+1), tav(n+1, vector<ll>(2, -1));
    vector<ll> a(k);

    for(ll &i : a) i = read();;

    for(ll i = 0; i < m; i++) {
        ll x,y;
        x = read(); y = read();
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<vector<ll> > pref(n+3, vector<ll>(2, 0));
    queue<pair<ll, ll >> sor;

    for(ll i = 0; i < k; i++) {
        if(!g[a[i]].empty()) {
            tav[a[i]][0] = 1;
            pref[1][0]++;
            sor.push({a[i], 0});
        }
        else {
            pref[1][0]++;
            pref[3][0]--;
            //cout << "empty: " << a[i] << endl;
        }
    }

    while(!sor.empty()) {
        pair<ll, ll> cur = sor.front();
        sor.pop();

        //cout << cur.first << ", " << cur.second << ": " << tav[cur.first][cur.second] << endl;

        for(ll sz : g[cur.first]) {
            if(tav[sz][1-cur.second] != -1) continue;
            tav[sz][1-cur.second] = tav[cur.first][cur.second] + 1;
            pref[tav[sz][1-cur.second]][1-cur.second]++;
            sor.push({sz, 1-cur.second});
        }
    }

    /*for(ll i = 1; i < 7; i++) cout << pref[i][0] << ' ';
    cout << endl;
    for(ll i = 1; i < 7; i++) cout << pref[i][1] << ' ';
    cout << endl;*/

    vector<ll> mo(n+3, 0);
    ll maxi = -1, ind = -1;
    for(ll i = 1; i < pref.size(); i++) { 
        mo[i] = pref[i][1-i%2];

        if(i > 2) mo[i] += mo[i-2];

        if(mo[i] > maxi) {
            maxi = mo[i];
            ind = i;
        }
    }

    cout << maxi << "\n" << ind << "\n";
    for(ll i = 1; i <= ind; i++) cout << mo[i] << ' ';
    cout << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base88/100
1Accepted0/03ms1860 KiB
2Accepted0/018ms12484 KiB
3Accepted2/21ms2260 KiB
4Accepted2/22ms2600 KiB
5Accepted2/22ms3004 KiB
6Accepted2/24ms4072 KiB
7Accepted4/44ms4108 KiB
8Accepted4/47ms5888 KiB
9Accepted4/46ms5988 KiB
10Accepted4/47ms6088 KiB
11Accepted4/420ms13192 KiB
12Accepted4/420ms13524 KiB
13Accepted4/430ms21008 KiB
14Accepted4/434ms21576 KiB
15Accepted6/659ms29276 KiB
16Accepted6/654ms30084 KiB
17Accepted6/679ms38004 KiB
18Accepted6/678ms39056 KiB
19Accepted6/678ms43504 KiB
20Accepted6/681ms44664 KiB
21Accepted6/685ms45812 KiB
22Accepted6/698ms46984 KiB
23Time limit exceeded0/6136ms54012 KiB
24Time limit exceeded0/6131ms54152 KiB