94332024-02-21 17:07:38PallanekPéterKaktuszgráfcpp17Wrong answer 0/504ms4668 KiB
#include<bits/stdc++.h>
using namespace std;

vector<vector<int>> graf;
vector<int> szin;
vector<int> p;
int mx=0;

int hossz(int a, int v){
    int h;
    while(a!=v){
        a=p[a]; h++;
    }
    return h+1;
}

void mk(int u){
    if (szin[u]==-1){
        szin[u]=0;
        for(int v:graf[u]){
            if (szin[v]==1){mx=max(mx,hossz(v,u));}
            if (szin[v]==-1){
                mk(v);
                p[v]=u;
            }
        }
    }
    szin[u]=1;
}

int main(){
    int n,m; cin >> n >> m;
    graf.resize(n);
    szin.assign(n,-1);
    p.resize(n);
    for(int i=0;i<m;i++){
        int u,v; cin >> u >> v;
        graf[u-1].push_back(v-1);
        graf[v-1].push_back(u-1);
    }
    mk(1); cout << mx;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1872 KiB
2Wrong answer0/03ms2152 KiB
3Wrong answer0/23ms2504 KiB
4Wrong answer0/23ms2840 KiB
5Wrong answer0/23ms2884 KiB
6Wrong answer0/23ms3100 KiB
7Wrong answer0/23ms3460 KiB
8Wrong answer0/23ms3260 KiB
9Wrong answer0/23ms3276 KiB
10Wrong answer0/23ms3588 KiB
11Wrong answer0/24ms3740 KiB
12Wrong answer0/23ms3696 KiB
13Wrong answer0/23ms3760 KiB
14Wrong answer0/23ms4156 KiB
15Wrong answer0/23ms4096 KiB
16Wrong answer0/23ms4144 KiB
17Wrong answer0/23ms4280 KiB
18Wrong answer0/24ms4208 KiB
19Wrong answer0/34ms4416 KiB
20Wrong answer0/33ms4400 KiB
21Wrong answer0/33ms4556 KiB
22Wrong answer0/33ms4548 KiB
23Wrong answer0/33ms4668 KiB
24Wrong answer0/33ms4556 KiB