제출 #799199

#제출 시각아이디문제언어결과실행 시간메모리
799199tlnk07Cijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
68 ms13220 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long

long long n, m, x, y, dis[100001], ans = 0;
vector<int> vec[100001];
bool check[100001];
pair<int, int> maxi;

void dfs(int x, int p, int h)
{
	check[x] = true;
	for(int c : vec[x])	if(c != p)	dfs(c, x, h + 1);
	if(maxi.first < h)	maxi = {h, x};
}

signed main()
{
	
	cin >> n >> m;
	while(m--)
	{
		cin >> x >> y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	for(int i = 1; i <= n; ++i)
	{
		if(!check[i])
		{
			check[i] = true;
			maxi = {-1, -1};
			dfs(i, 0, 1);
			dfs(maxi.second, 0, 1);
			ans += maxi.first;
		}
	}
	cout << ans;
}
#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...