Submission #799177

# Submission time Handle Problem Language Result Execution time Memory
799177 2023-07-31T10:32:58 Z tlnk07 Cijanobakterije (COCI21_cijanobakterije) C++17
12 / 70
52 ms 14808 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

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

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])
		{
			priority_queue<int> pri;
			for(int c : vec[i])
			{
				maxi = -1;
				dfs(c, i, 1);
				pri.push(maxi);
			}
			int cnt = 0;
			while(!pri.empty() && cnt < 2)
			{
				ans += pri.top();
				++cnt;
				pri.pop();
			}
			++ans;
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 14808 KB Output is correct
2 Correct 5 ms 3156 KB Output is correct
3 Correct 10 ms 3624 KB Output is correct
4 Correct 14 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2656 KB Output is correct
5 Correct 7 ms 3352 KB Output is correct
6 Correct 12 ms 4236 KB Output is correct
7 Correct 17 ms 5104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -