Submission #563710

# Submission time Handle Problem Language Result Execution time Memory
563710 2022-05-18T03:36:30 Z racsosabe Shymbulak (IZhO14_shymbulak) C++14
50 / 100
510 ms 676 KB
#include<bits/stdc++.h>
using namespace::std;

const int N = 5000 + 5;

int n;
int D[N];
int cnt[N];
vector<int> G[N];

pair<int, int> BFS(int src){
	memset(D, -1, sizeof D);
	memset(cnt, 0, sizeof cnt);
	D[src] = 0;
	queue<int> Q;
	Q.emplace(src);
	cnt[src] = 1;
	while(!Q.empty()){
		int u = Q.front(); Q.pop();
		for(int v : G[u]){
			if(~D[v]){
				if(D[v] == D[u] + 1) cnt[v] += cnt[u];
				continue;
			}
			D[v] = D[u] + 1;
			cnt[v] = cnt[u];
			Q.emplace(v);
		}
	}
	int maxi = *max_element(D + 1, D + n + 1);
	int r = 0;
	for(int i = 1; i <= n; i++) if(maxi == D[i]) r += cnt[i];
	return {maxi, r};
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	int ans = 0;
	int best = -1;
	for(int i = 1; i <= n; i++){
		pair<int, int> cur = BFS(i);
		if(best == cur.first) ans += cur.second;
		else if(best < cur.first){
			best = cur.first;
			ans = cur.second;
		}
	}
	cout << ans / 2 << endl;
	return 0;
}

Compilation message

shymbulak.cpp: In function 'int main()':
shymbulak.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
shymbulak.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 424 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 476 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 17 ms 468 KB Output is correct
4 Correct 17 ms 496 KB Output is correct
5 Correct 408 ms 596 KB Output is correct
6 Correct 250 ms 676 KB Output is correct
7 Correct 510 ms 648 KB Output is correct
8 Correct 424 ms 664 KB Output is correct
9 Correct 419 ms 640 KB Output is correct
10 Correct 443 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -