166192025-05-07 07:03:57csdavidPletykacpp17Wrong answer 0/1008ms820 KiB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n, m, pletykaszam;
struct cella{
    int szin=0, bejart=0;
    vector<int> barat;
};

cella a[10001];

int szinez(int x){
    int kezd=x;
    a[x].szin=1;
    queue<int> q;
    q.push(x);
    while(!q.empty()){
        x=q.front();
        q.pop();
        for(int& it:a[x].barat){
            if(a[x].szin==2&&a[it].szin!=2){
                a[it].szin=2;
                q.push(it);
            }
            else if(a[x].szin*a[it].szin==-1){
                a[x].szin=2;
                a[it].szin=2;
                q.push(it);
            }
            else if(a[it].szin==0){
                a[it].szin=-a[x].szin;
                q.push(it);
            }
        }
    }
    int g[3]={0, 0, 0};
    a[kezd].bejart=1;
    q.push(kezd);
    while(!q.empty()){
        x=q.front();
        q.pop();
        if(a[x].szin==-1){
            g[0]++;
        }
        else{
            g[a[x].szin]++;
        }
        for(auto& it:a[x].barat){
            if(a[it].bejart==0){
                a[it].bejart=1;
                q.push(it);
            }
        }
    }
    return max(g[0], max(g[1], g[2]));
}

int main()
{
    int maxi=0;
    int x, y;
    cin >> n >> m >> pletykaszam;
    int ismero[pletykaszam];
    for(int i=0; i<pletykaszam; i++){
        cin >> ismero[i];
    }
    for(int i=0; i<m; i++){
        cin >> x >> y;
        a[x].barat.push_back(y);
        a[y].barat.push_back(x);
    }
    for(int i=1; i<=n; i++){
        if(a[i].szin==0){
            maxi+=szinez(i);
        }
    }
    cout << maxi;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/01ms756 KiB
2Runtime error0/01ms564 KiB
3Wrong answer0/21ms564 KiB
4Wrong answer0/22ms564 KiB
5Wrong answer0/23ms564 KiB
6Wrong answer0/24ms712 KiB
7Wrong answer0/44ms776 KiB
8Wrong answer0/48ms820 KiB
9Wrong answer0/48ms820 KiB
10Wrong answer0/48ms820 KiB
11Runtime error0/41ms756 KiB
12Runtime error0/41ms636 KiB
13Runtime error0/41ms564 KiB
14Runtime error0/41ms564 KiB
15Runtime error0/61ms564 KiB
16Runtime error0/61ms564 KiB
17Runtime error0/61ms564 KiB
18Runtime error0/61ms564 KiB
19Runtime error0/61ms564 KiB
20Runtime error0/61ms564 KiB
21Runtime error0/61ms756 KiB
22Runtime error0/61ms564 KiB
23Runtime error0/61ms748 KiB
24Runtime error0/61ms564 KiB