Submission #344671

# Submission time Handle Problem Language Result Execution time Memory
344671 2021-01-06T07:25:03 Z maskoff Shymbulak (IZhO14_shymbulak) C++14
50 / 100
1500 ms 21868 KB
#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;

const int N = 6e5 + 5;

int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};

int n, mx;
vector<int> g[N], ans(N);

void go(int x) {
	vector<int> dp(n + 1, 1e9), cnt(n + 1);
	cnt[x] = 1;
	dp[x] = 0;
	queue<int> q;
	q.push(x);
	while (!q.empty()) {
	 	int v = q.front();
	 	q.pop();
	 	for (int to : g[v]) {
	 	 	if (dp[to] == dp[v] + 1) {
	 	 	 	cnt[to] += cnt[v];
	 	 	 	continue;
	 	 	}
	 	 	if (dp[to] > dp[v] + 1) {
	 	 		cnt[to] = cnt[v];
	 	 	 	dp[to] = dp[v] + 1;
	 	 	 	q.push(to);
	 	 	}
	 	}
	}
	//cerr << x << "\n";
	for (int i = 1; i <= n; i++) {
	 	//cerr << i << " " << dp[i] << " " << cnt[i] << endl;
	 	ans[dp[i]] += cnt[i];
	 	mx = max(mx, dp[i]);
	}
	cerr << endl;
}

int main() {
	ios_base :: sync_with_stdio(false);               
	cin.tie(nullptr);
	srand(time(nullptr));
	cin >> n;
	for (int i = 1; i <= n; i++) {
	 	int x, y;
	 	cin >> x >> y;
	 	g[x].pb(y);
	 	g[y].pb(x);
	}
	for (int i = 1; i <= n; i++) {
	 	go(i);
	}
	cout << ans[mx] / 2;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 12 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 12 ms 16748 KB Output is correct
5 Correct 12 ms 16748 KB Output is correct
6 Correct 13 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 12 ms 16748 KB Output is correct
9 Correct 14 ms 16748 KB Output is correct
10 Correct 12 ms 16876 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 13 ms 16748 KB Output is correct
13 Correct 13 ms 16748 KB Output is correct
14 Correct 19 ms 16748 KB Output is correct
15 Correct 19 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 16748 KB Output is correct
2 Correct 22 ms 16876 KB Output is correct
3 Correct 43 ms 16876 KB Output is correct
4 Correct 43 ms 16876 KB Output is correct
5 Correct 575 ms 17132 KB Output is correct
6 Correct 505 ms 17124 KB Output is correct
7 Correct 703 ms 17088 KB Output is correct
8 Correct 669 ms 17108 KB Output is correct
9 Correct 590 ms 17096 KB Output is correct
10 Correct 654 ms 17004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1562 ms 21868 KB Time limit exceeded
2 Halted 0 ms 0 KB -