Submission #250044

# Submission time Handle Problem Language Result Execution time Memory
250044 2020-07-16T17:39:06 Z srvlt Shymbulak (IZhO14_shymbulak) C++14
0 / 100
82 ms 15224 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 5003, inf = 1e8;
int n, d[n0][n0], w[n0][n0], used[n0][n0], cnt[n0];
vector <int> g[n0];
queue <int> q;

void bfs(int s) {
	q.push(s);
	w[s][s] = 1;
	used[s][s] = 1;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int to : g[v]) {
			if (used[s][to]) continue;
			used[s][to] = 1;
			if (d[s][to] == d[s][v] + 1) {
				w[s][to] += w[s][v];
			}	else {
				d[s][to] = d[s][v] + 1;
				w[s][to] = w[s][v];
				q.push(to);
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	
	int tc;
	//cin >> tc;
	tc = 1;
	while (tc--) {
		//string st;
		//cin >> st;
		//cout << st << '\n';
		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++) {
			bfs(i);
			for (int j = 1; j <= n; j++) {
				cnt[d[i][j]] += w[i][j];
			}
		}
		int ans = -1;
		for (int i = n; i >= 1; i--) {
			if (cnt[i]) {
				ans = cnt[i];
				break;
			}
		}
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Incorrect 0 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 14720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 15224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -