12222022-03-27 11:39:00Szin AttilaPletykacpp14Időlimit túllépés 76/100160ms49476 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 int maxN = 2e5 + 5;
const int 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;
    
    int n,m,k;
    n = read(); m = read(); k = read();

    vector<vector<int> > g(n+1);
    vector<vector<bool> > volt(n+1, vector<bool>(2, 0));
    vector<int> a(k);

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

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

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

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

    int last = -1;

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

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

        for(int sz : g[cur.first]) {
            if(volt[sz][cur.second % 2]) continue;
            volt[sz][cur.second % 2] = 1;
            pref[cur.second + 1][cur.second % 2]++;
            last = cur.second + 1;
            sor.push({sz, cur.second + 1});
        }
    }

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

    vector<int> mo(n+3, 0);
    int maxi = -1, ind = -1;
    for(int i = 1; i <= last; 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(int i = 1; i <= ind; i++) cout << mo[i] << ' ';
    cout << "\n";

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base76/100
1Elfogadva0/02ms1820 KiB
2Elfogadva0/021ms13268 KiB
3Elfogadva2/21ms2224 KiB
4Elfogadva2/22ms2540 KiB
5Elfogadva2/23ms2964 KiB
6Elfogadva2/24ms3920 KiB
7Elfogadva4/44ms3972 KiB
8Elfogadva4/48ms5844 KiB
9Elfogadva4/47ms5948 KiB
10Elfogadva4/48ms6044 KiB
11Elfogadva4/423ms14016 KiB
12Elfogadva4/419ms14344 KiB
13Elfogadva4/439ms22088 KiB
14Elfogadva4/437ms22656 KiB
15Elfogadva6/659ms30844 KiB
16Elfogadva6/661ms31644 KiB
17Elfogadva6/6108ms40056 KiB
18Elfogadva6/6101ms41104 KiB
19Elfogadva6/693ms45932 KiB
20Elfogadva6/6104ms47104 KiB
21Időlimit túllépés0/6133ms48272 KiB
22Időlimit túllépés0/6136ms49476 KiB
23Időlimit túllépés0/6160ms32724 KiB
24Időlimit túllépés0/6136ms32660 KiB