Submission #316648

# Submission time Handle Problem Language Result Execution time Memory
316648 2020-10-27T01:35:52 Z shrek12357 Shymbulak (IZhO14_shymbulak) C++14
50 / 100
630 ms 888 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 

const int MAXN = 5005;
int n;
vector<int> adjList[MAXN];

int cur = 0, cnt = 0;

void bfs(int src) {
	int dist[MAXN];
	for (int i = 0; i < MAXN; i++) {
		dist[i] = INT_MAX;
	}
	queue<int> q;
	q.push(src);
	dist[src] = 0;
	while (q.size() > 0) {
		int cn = q.front();
		q.pop();
		for (auto i : adjList[cn]) {
			if (dist[i] >= dist[cn] + 1) {
				q.push(i);
				dist[i] = dist[cn] + 1;
				if (cur == dist[i]) {
					cnt++;
				}
				else if (cur < dist[i]) {
					cur = dist[i];
					cnt = 1;
				}
			}
		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adjList[a].push_back(b);
		adjList[b].push_back(a);
	}
	int ans = 0, best = 0;
	for (int i = 0; i < n; i++) {
		cur = 0;
		cnt = 0;
		bfs(i);
		if (cur == ans) {
			best += cnt;
		}
		else if (cur > ans) {
			ans = cur;
			best = cnt;
		}
	}
	cout << best/2 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 22 ms 512 KB Output is correct
4 Correct 25 ms 640 KB Output is correct
5 Correct 488 ms 640 KB Output is correct
6 Correct 334 ms 760 KB Output is correct
7 Correct 582 ms 640 KB Output is correct
8 Correct 518 ms 888 KB Output is correct
9 Correct 499 ms 760 KB Output is correct
10 Correct 630 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -