96152024-02-23 14:37:45PallanekPéterKaktuszgráfcpp14Wrong answer 21/504ms4412 KiB
#include<bits/stdc++.h>
using namespace std;

vector<int> graf[1001];
bool seen[1001];
vector<int> szin;
int p[1001];
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 (!seen[u]){
        szin[u]=0;
        seen[u]=true;
        for(int v:graf[u]){
            if (szin[v]==1) mx=max(mx,hossz(v,u));
            if (!seen[v]){
                mk(v);
                p[v]=u;
            }
        }
    }
    szin[u]=1;
}

int main(){
    int n,m; cin >> n >> m;
    szin.assign(n+1,-1);
    for(int i=0;i<m;i++){
        int u,v; cin >> u >> v;
        graf[u].push_back(v);
        graf[v].push_back(u);
    }
    mk(1);
    cout << mx;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1776 KiB
2Wrong answer0/03ms2136 KiB
3Accepted2/23ms2304 KiB
4Wrong answer0/23ms2620 KiB
5Wrong answer0/23ms2588 KiB
6Wrong answer0/23ms2740 KiB
7Accepted2/23ms3068 KiB
8Accepted2/23ms3336 KiB
9Wrong answer0/23ms3288 KiB
10Wrong answer0/23ms3520 KiB
11Wrong answer0/23ms3420 KiB
12Wrong answer0/24ms3736 KiB
13Wrong answer0/23ms3876 KiB
14Wrong answer0/23ms3828 KiB
15Wrong answer0/23ms3832 KiB
16Wrong answer0/23ms3740 KiB
17Wrong answer0/23ms3800 KiB
18Wrong answer0/24ms4060 KiB
19Wrong answer0/34ms4016 KiB
20Accepted3/33ms4020 KiB
21Accepted3/33ms4164 KiB
22Accepted3/33ms4180 KiB
23Accepted3/33ms4188 KiB
24Accepted3/33ms4412 KiB