# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
496535 | kappa | Cijanobakterije (COCI21_cijanobakterije) | C++14 | 105 ms | 13892 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, vis[100005];
vector<int> d[100005];
pair<int, int> furthest(int ind, int parent = -1){
vis[ind] = 1;
pair<int, int> ret(ind, 1);
for (int i = 0; i < d[ind].size(); i++)
{
if(d[ind][i] != parent){
pair<int, int> a = furthest(d[ind][i], ind);
a.second++;
if(a.second > ret.second){
ret = a;
}
}
}
return ret;
}
int diameter(int ind){
pair<int, int> s1 = furthest(ind);
return furthest(s1.first).second;
}
int main(){
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
d[u].push_back(v);
d[v].push_back(u);
}
for (int i = 1; i <= n; i++)
{
if(!vis[i]){
ans += diameter(i);
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |