Submission #499124

# Submission time Handle Problem Language Result Execution time Memory
499124 2021-12-27T09:05:12 Z boykut Shymbulak (IZhO14_shymbulak) C++14
0 / 100
1500 ms 5948 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	srand(time(NULL));

	int n;
	cin >> n;

	vector<int> g[n];

	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	int ansdist = 0, cntans = 0;
	for (int i = 0; i < n; i++) {
		vector<int> d(n, INT_MAX);
		queue<int> q;
		q.push(i);
		d[i] = 0;
		int maxdist = 0, cntdist = 0;
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto u : g[v]) {
				if (d[u] >= d[v] + 1) {
					d[u] = d[v] + 1;
					q.push(u);
					if (d[u] == maxdist)
						cntdist++;
					if (d[u] > maxdist) {
						maxdist = d[u];
						cntdist = 1;
					}
				}
			}
		}
		if (maxdist == ansdist)
			cntans += cntdist;
		if (maxdist > ansdist) {
			ansdist = maxdist;
			cntans = cntdist;
		}
	}

	assert(cntans == 2 || cntans == 4);

	cout << cntans / 2 << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1580 ms 5948 KB Time limit exceeded
2 Halted 0 ms 0 KB -