12162022-03-25 20:03:21Szin AttilaPletykacpp14Időlimit túllépés 88/100194ms54216 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;


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

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

    for(ll &i : a) cin >> i;

    for(ll i = 0; i < m; i++) {
        ll x,y;
        cin >> x >> y;
        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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base88/100
1Elfogadva0/02ms1860 KiB
2Elfogadva0/028ms12552 KiB
3Elfogadva2/21ms2280 KiB
4Elfogadva2/22ms2592 KiB
5Elfogadva2/22ms2904 KiB
6Elfogadva2/24ms4092 KiB
7Elfogadva4/44ms4092 KiB
8Elfogadva4/48ms5800 KiB
9Elfogadva4/48ms5896 KiB
10Elfogadva4/48ms5972 KiB
11Elfogadva4/428ms13300 KiB
12Elfogadva4/425ms13632 KiB
13Elfogadva4/441ms21064 KiB
14Elfogadva4/450ms21648 KiB
15Elfogadva6/682ms29336 KiB
16Elfogadva6/671ms30164 KiB
17Elfogadva6/6103ms38116 KiB
18Elfogadva6/6108ms39160 KiB
19Elfogadva6/6103ms43552 KiB
20Elfogadva6/693ms44716 KiB
21Elfogadva6/693ms45868 KiB
22Elfogadva6/6111ms47048 KiB
23Időlimit túllépés0/6194ms32596 KiB
24Időlimit túllépés0/6168ms54216 KiB