Submission #250044

#TimeUsernameProblemLanguageResultExecution timeMemory
250044srvltShymbulak (IZhO14_shymbulak)C++14
0 / 100
82 ms15224 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...