Submission #557372

# Submission time Handle Problem Language Result Execution time Memory
557372 2022-05-05T08:33:11 Z new_acc Cijanobakterije (COCI21_cijanobakterije) C++14
15 / 70
217 ms 32768 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[N],maxi,g;
bitset<N>vis;
vi graf[N];
void dfs(int v,int o,int gl){
    vis[v]=1;
    if(gl>maxi) maxi=gl,g=v;
    for(auto u:graf[v]){
        if(u==o) continue;
        dfs(u,v,gl+1);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int a,b,i=1;i<=m;i++){
        cin>>a>>b;
        graf[a].push_back(b),graf[b].push_back(a);
    }
    int res=0;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        dfs(i,i,0);
        maxi=0;
        dfs(g,g,0);
        res+=maxi+1;
        maxi=0;
    }
    cout<<res<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24532 KB Output is correct
2 Correct 23 ms 25248 KB Output is correct
3 Correct 29 ms 25904 KB Output is correct
4 Correct 36 ms 26636 KB Output is correct
5 Correct 44 ms 27468 KB Output is correct
6 Correct 53 ms 28216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 32768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23780 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23808 KB Output is correct
5 Incorrect 217 ms 24424 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Incorrect 12 ms 23764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24532 KB Output is correct
2 Correct 23 ms 25248 KB Output is correct
3 Correct 29 ms 25904 KB Output is correct
4 Correct 36 ms 26636 KB Output is correct
5 Correct 44 ms 27468 KB Output is correct
6 Correct 53 ms 28216 KB Output is correct
7 Incorrect 117 ms 32768 KB Output isn't correct
8 Halted 0 ms 0 KB -