답안 #880159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880159 2023-11-28T22:11:51 Z JoksimKaktus Cijanobakterije (COCI21_cijanobakterije) C++17
15 / 70
111 ms 10616 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";}

vector <int> adj[100005];
int point = 1;
int maxi = 1;
vector <bool> vis(100005);

void dfs(int i,int p,int cur){
    vis[i]=true;
    if(cur > maxi){
        maxi = cur;
        point = i;
    }
    for(int j : adj[i]){
        if(j != p){
            dfs(j,i,cur+1);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int res = 0;
    for(int i = 1;i <= n;i++){
        if(!vis[i]){
            dfs(i,-1,1);
            dfs(point,-1,1);
            res += maxi;
            maxi = 1;
            point = 1;
        }
    }
    cout << res << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3164 KB Output is correct
2 Correct 8 ms 3676 KB Output is correct
3 Correct 12 ms 4440 KB Output is correct
4 Correct 17 ms 4956 KB Output is correct
5 Correct 20 ms 5468 KB Output is correct
6 Correct 23 ms 5976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 10616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Incorrect 111 ms 3420 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2820 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Incorrect 1 ms 2648 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3164 KB Output is correct
2 Correct 8 ms 3676 KB Output is correct
3 Correct 12 ms 4440 KB Output is correct
4 Correct 17 ms 4956 KB Output is correct
5 Correct 20 ms 5468 KB Output is correct
6 Correct 23 ms 5976 KB Output is correct
7 Incorrect 72 ms 10616 KB Output isn't correct
8 Halted 0 ms 0 KB -