/**
* author: Haunted_Cpp
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const int MAX_N = 5000 + 5;
const int MAX_K = 2000 + 5;
vector<vector<int>> g(MAX_N);
vector<double> ans(MAX_N);
int solve(int node, int target, const vector<vector<int>> &dag, vector<int> &dp) {
if (node == target) return 1;
int &res = dp[node];
if (~res) return res;
res = 0;
for (auto to : dag[node]) {
res += solve(to, target, dag, dp);
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int st, et;
cin >> st >> et;
g[st].emplace_back(et);
g[et].emplace_back(st);
}
vector<vector<int>> a, b;
auto bfs = [&](int source, int sink) {
a.clear();
b.clear();
a.resize(MAX_N);
b.resize(MAX_N);
queue<int> q;
vector<int> dist(n, 1e9);
dist[sink] = 0;
q.push(sink);
while(!q.empty()) {
int node = q.front();
q.pop();
for (auto to : g[node]) {
if (dist[to] > dist[node] + 1) {
dist[to] = dist[node] + 1;
q.push(to);
}
}
}
function<void(int)> build_dag = [&](int node) {
const int cur = dist[node];
for (auto to : g[node]) {
if (dist[to] == cur - 1) {
a[node].emplace_back(to);
b[to].emplace_back(node);
build_dag(to);
}
}
};
build_dag(source);
for (int i = 0; i < MAX_N; i++) {
sort(a[i].begin(), a[i].end());
sort(b[i].begin(), b[i].end());
a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());
b[i].erase(unique(b[i].begin(), b[i].end()), b[i].end());
}
};
int k;
cin >> k;
vector<int> dp_a, dp_b;
while(k--) {
int source, sink;
cin >> source >> sink;
bfs(source, sink);
dp_a = dp_b = vector<int>(MAX_N, -1);
const int cnt_shortest = solve(source, sink, a, dp_a);
if (cnt_shortest == 0) continue;
for (int i = 0; i < n; i++) {
int L = solve(i, sink, a, dp_a);
int R = solve(i, source, b, dp_b);
ans[i] += 1.0 * L / cnt_shortest * R;
}
}
cout << (max_element(ans.begin(), ans.end()) - ans.begin()) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
14 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
896 KB |
Output is correct |
10 |
Correct |
23 ms |
896 KB |
Output is correct |
11 |
Correct |
28 ms |
896 KB |
Output is correct |
12 |
Correct |
25 ms |
768 KB |
Output is correct |
13 |
Correct |
44 ms |
768 KB |
Output is correct |
14 |
Correct |
49 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
14 ms |
896 KB |
Output is correct |
16 |
Correct |
19 ms |
896 KB |
Output is correct |
17 |
Correct |
23 ms |
896 KB |
Output is correct |
18 |
Correct |
28 ms |
896 KB |
Output is correct |
19 |
Correct |
25 ms |
768 KB |
Output is correct |
20 |
Correct |
44 ms |
768 KB |
Output is correct |
21 |
Correct |
49 ms |
1016 KB |
Output is correct |
22 |
Correct |
15 ms |
768 KB |
Output is correct |
23 |
Correct |
18 ms |
768 KB |
Output is correct |
24 |
Correct |
22 ms |
768 KB |
Output is correct |
25 |
Correct |
27 ms |
768 KB |
Output is correct |
26 |
Correct |
30 ms |
768 KB |
Output is correct |
27 |
Correct |
43 ms |
888 KB |
Output is correct |
28 |
Correct |
49 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
3 ms |
896 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
12 ms |
896 KB |
Output is correct |
18 |
Correct |
8 ms |
768 KB |
Output is correct |
19 |
Correct |
10 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
14 ms |
896 KB |
Output is correct |
16 |
Correct |
19 ms |
896 KB |
Output is correct |
17 |
Correct |
23 ms |
896 KB |
Output is correct |
18 |
Correct |
28 ms |
896 KB |
Output is correct |
19 |
Correct |
25 ms |
768 KB |
Output is correct |
20 |
Correct |
44 ms |
768 KB |
Output is correct |
21 |
Correct |
49 ms |
1016 KB |
Output is correct |
22 |
Correct |
15 ms |
768 KB |
Output is correct |
23 |
Correct |
18 ms |
768 KB |
Output is correct |
24 |
Correct |
22 ms |
768 KB |
Output is correct |
25 |
Correct |
27 ms |
768 KB |
Output is correct |
26 |
Correct |
30 ms |
768 KB |
Output is correct |
27 |
Correct |
43 ms |
888 KB |
Output is correct |
28 |
Correct |
49 ms |
876 KB |
Output is correct |
29 |
Correct |
3 ms |
896 KB |
Output is correct |
30 |
Correct |
2 ms |
768 KB |
Output is correct |
31 |
Correct |
12 ms |
896 KB |
Output is correct |
32 |
Correct |
8 ms |
768 KB |
Output is correct |
33 |
Correct |
10 ms |
896 KB |
Output is correct |
34 |
Correct |
5 ms |
896 KB |
Output is correct |
35 |
Correct |
3 ms |
768 KB |
Output is correct |
36 |
Correct |
164 ms |
896 KB |
Output is correct |
37 |
Correct |
404 ms |
1024 KB |
Output is correct |
38 |
Correct |
1094 ms |
1284 KB |
Output is correct |
39 |
Correct |
1692 ms |
1272 KB |
Output is correct |
40 |
Correct |
152 ms |
1024 KB |
Output is correct |
41 |
Correct |
716 ms |
1560 KB |
Output is correct |
42 |
Correct |
1605 ms |
1596 KB |
Output is correct |
43 |
Correct |
94 ms |
896 KB |
Output is correct |
44 |
Correct |
80 ms |
1024 KB |
Output is correct |