제출 #814821

#제출 시각아이디문제언어결과실행 시간메모리
814821exodus_Cijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
74 ms10472 KiB
#include<bits/stdc++.h> using namespace std; vector<int>adj[100001]; bool vis[100001]={false}; int again, maxdepth; void dfs(int current, int past, int depth) { vis[current]=true; if(depth>maxdepth) { maxdepth=depth; again=current; } for(auto iter:adj[current]) { if(iter != past) { dfs(iter, current, depth+1); } } } int longest(int i) { maxdepth=0; dfs(i, -1, 1); maxdepth=0; dfs(again, -1, 1); return maxdepth; } int main() { int N,M,A,B; cin >> N >> M; for(int i=1; i<=M; i++) { cin >> A >> B; adj[A].push_back(B); adj[B].push_back(A); } int sum=0; for(int i=1; i<=N; i++) { if(vis[i]==false) { sum+=longest(i); } } cout << sum << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...