Submission #948844

# Submission time Handle Problem Language Result Execution time Memory
948844 2024-03-18T15:28:48 Z vin Cijanobakterije (COCI21_cijanobakterije) C++17
15 / 70
31 ms 12124 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 2147483645;
const int maxN = (int)1e5+5;
const ll LLINF = LLONG_MAX;
//const ll mod = 998244353;
const ll mod = 1000000007;

vector<int> adj[maxN];
int dist[maxN];
bool vis[maxN];

void dfs(int s) {
	for (auto i: adj[s]) {
		if (vis[i]) continue;
		vis[i] = true;
		dist[i] = dist[s]+1;
		dfs(i);
	}
}

void solv() {
	int n, m, a, b;
	cin>>n>>m;
	for (int i=0;i<n-1;i++) {
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1);
	int mx = 0, start = 1;
	for (int i=1;i<=n;i++) {
		if (dist[i] > mx) {
			mx = dist[i];
			start = i;
		}
	}
	memset(dist, 0, sizeof dist);
	memset(vis, 0, sizeof vis);
	dfs(start);
	mx = 0;
	for (int i=1;i<=n;i++) {
		mx = max(mx, dist[i]);
	}
	cout<<mx+1<<'\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t=1;
//    cin>>t;
    while (t--) solv();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3932 KB Output is correct
2 Correct 9 ms 4700 KB Output is correct
3 Correct 14 ms 5372 KB Output is correct
4 Correct 17 ms 5980 KB Output is correct
5 Correct 22 ms 6748 KB Output is correct
6 Correct 26 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 12124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 5976 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Incorrect 1 ms 3164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3932 KB Output is correct
2 Correct 9 ms 4700 KB Output is correct
3 Correct 14 ms 5372 KB Output is correct
4 Correct 17 ms 5980 KB Output is correct
5 Correct 22 ms 6748 KB Output is correct
6 Correct 26 ms 7516 KB Output is correct
7 Incorrect 31 ms 12124 KB Output isn't correct
8 Halted 0 ms 0 KB -