Submission #947706

# Submission time Handle Problem Language Result Execution time Memory
947706 2024-03-16T22:27:21 Z Isam Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
30 ms 18116 KB
#include<bits/stdc++.h>
using namespace std;

int n, m, mxnode, maxd;
vector<int> g[100001];
bool vis[100001];

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(register int i = 1, u, v; i <= m; ++i){
		cin >> u >> v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	function<void(int, int, bool, int)> Dfs = [&](int node,int len, bool f, int fa){
		if(f) vis[node] = true;
		if(maxd < len){
			maxd = len, mxnode = node;
		}
		for(int &to : g[node]){
			if(vis[to] || to == fa) continue;
			Dfs(to, len + 1, f, node);
		}
		return;
	};
	int ans(0);
	for(register int i = 1; i <= n; ++i){
		if(vis[i]) continue;
		maxd = 0;
		Dfs(i, 0, 0, i);
		Dfs(mxnode, 0, 1, mxnode);
		ans += maxd + 1;
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |  for(register int i = 1, u, v; i <= m; ++i){
      |                   ^
Main.cpp:11:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |  for(register int i = 1, u, v; i <= m; ++i){
      |                          ^
Main.cpp:11:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |  for(register int i = 1, u, v; i <= m; ++i){
      |                             ^
Main.cpp:28:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   28 |  for(register int i = 1; i <= n; ++i){
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 9 ms 4188 KB Output is correct
3 Correct 15 ms 4876 KB Output is correct
4 Correct 18 ms 5644 KB Output is correct
5 Correct 23 ms 6484 KB Output is correct
6 Correct 29 ms 7280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 18116 KB Output is correct
2 Correct 3 ms 3168 KB Output is correct
3 Correct 5 ms 3676 KB Output is correct
4 Correct 8 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 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 2652 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 8 ms 4700 KB Output is correct
# Verdict Execution time Memory 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 9 ms 4188 KB Output is correct
3 Correct 15 ms 4876 KB Output is correct
4 Correct 18 ms 5644 KB Output is correct
5 Correct 23 ms 6484 KB Output is correct
6 Correct 29 ms 7280 KB Output is correct
7 Correct 28 ms 18116 KB Output is correct
8 Correct 3 ms 3168 KB Output is correct
9 Correct 5 ms 3676 KB Output is correct
10 Correct 8 ms 4184 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 5 ms 3932 KB Output is correct
17 Correct 8 ms 4700 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2648 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 30 ms 7088 KB Output is correct
30 Correct 6 ms 3932 KB Output is correct
31 Correct 18 ms 6748 KB Output is correct
32 Correct 11 ms 4596 KB Output is correct
33 Correct 23 ms 7004 KB Output is correct
34 Correct 15 ms 5468 KB Output is correct
35 Correct 19 ms 6748 KB Output is correct
36 Correct 21 ms 5980 KB Output is correct
37 Correct 22 ms 6992 KB Output is correct
38 Correct 24 ms 6584 KB Output is correct
39 Correct 19 ms 6748 KB Output is correct