#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fa(i,a,b) for(ll i = a; i >= b; i--)
const int N = 5005;
const int inf = 2e9;
int a[N], b[N], n, m, d[N][N];
ld c[N][N];
vector <int> adj[N];
void dfs(int u){
f(i,1,n+1) d[u][i] = inf;
d[u][u] = 0;
queue <int> q;
q.push(u);
c[u][u] = 1;
while(!q.empty()){
int v = q.front(); q.pop();
for(int f: adj[v]){
if(d[u][f] > d[u][v] + 1){
d[u][f] = d[u][v] + 1;
c[u][f] = c[u][v];
q.push(f);
}
else if(d[u][f] == d[u][v] + 1) c[u][f] += c[u][v];
}
}
}
int main(){
cin >> n >> m;
f(i,0,m){
int x, y; cin >> x >> y;
x++, y++;
adj[x].push_back(y), adj[y].push_back(x);
}
f(i,1,n+1) dfs(i);
int k, ans = 0; cin >> k;
f(i,1,k+1) {
cin >> a[i] >> b[i];
a[i]++, b[i]++;
}
ld ANS = 0;
f(i,1,n+1){
ld res = 0;
f(j,1,k+1){
if(d[a[j]][b[j]] == d[a[j]][i] + d[i][b[j]]){
res += (c[a[j]][i]*c[i][b[j]]) / c[a[j]][b[j]];
}
}
if(res > ANS){
ANS = res;
ans = i;
}
}
cout << --ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
3668 KB |
Output is correct |
9 |
Correct |
13 ms |
10388 KB |
Output is correct |
10 |
Correct |
25 ms |
20340 KB |
Output is correct |
11 |
Correct |
1 ms |
1444 KB |
Output is correct |
12 |
Correct |
1 ms |
676 KB |
Output is correct |
13 |
Correct |
6 ms |
5076 KB |
Output is correct |
14 |
Correct |
14 ms |
12700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
8 |
Correct |
6 ms |
5332 KB |
Output is correct |
9 |
Correct |
15 ms |
12876 KB |
Output is correct |
10 |
Correct |
13 ms |
10844 KB |
Output is correct |
11 |
Correct |
21 ms |
20928 KB |
Output is correct |
12 |
Correct |
2 ms |
1620 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
6 ms |
5444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
3668 KB |
Output is correct |
9 |
Correct |
13 ms |
10388 KB |
Output is correct |
10 |
Correct |
25 ms |
20340 KB |
Output is correct |
11 |
Correct |
1 ms |
1444 KB |
Output is correct |
12 |
Correct |
1 ms |
676 KB |
Output is correct |
13 |
Correct |
6 ms |
5076 KB |
Output is correct |
14 |
Correct |
14 ms |
12700 KB |
Output is correct |
15 |
Correct |
6 ms |
5332 KB |
Output is correct |
16 |
Correct |
15 ms |
12876 KB |
Output is correct |
17 |
Correct |
13 ms |
10844 KB |
Output is correct |
18 |
Correct |
21 ms |
20928 KB |
Output is correct |
19 |
Correct |
2 ms |
1620 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
5444 KB |
Output is correct |
22 |
Correct |
7 ms |
7124 KB |
Output is correct |
23 |
Correct |
6 ms |
5544 KB |
Output is correct |
24 |
Correct |
16 ms |
13428 KB |
Output is correct |
25 |
Correct |
35 ms |
24476 KB |
Output is correct |
26 |
Correct |
31 ms |
21580 KB |
Output is correct |
27 |
Correct |
2 ms |
1836 KB |
Output is correct |
28 |
Correct |
8 ms |
7340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
3668 KB |
Output is correct |
9 |
Correct |
13 ms |
10388 KB |
Output is correct |
10 |
Correct |
25 ms |
20340 KB |
Output is correct |
11 |
Correct |
1 ms |
1444 KB |
Output is correct |
12 |
Correct |
1 ms |
676 KB |
Output is correct |
13 |
Correct |
6 ms |
5076 KB |
Output is correct |
14 |
Correct |
14 ms |
12700 KB |
Output is correct |
15 |
Correct |
18 ms |
2180 KB |
Output is correct |
16 |
Correct |
18 ms |
7556 KB |
Output is correct |
17 |
Correct |
77 ms |
16352 KB |
Output is correct |
18 |
Correct |
44 ms |
14004 KB |
Output is correct |
19 |
Correct |
80 ms |
25164 KB |
Output is correct |
20 |
Correct |
12 ms |
3188 KB |
Output is correct |
21 |
Correct |
4 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
21 ms |
19640 KB |
Output is correct |
3 |
Correct |
19 ms |
17068 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
4756 KB |
Output is correct |
6 |
Correct |
3 ms |
3540 KB |
Output is correct |
7 |
Correct |
10 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
3668 KB |
Output is correct |
9 |
Correct |
13 ms |
10388 KB |
Output is correct |
10 |
Correct |
25 ms |
20340 KB |
Output is correct |
11 |
Correct |
1 ms |
1444 KB |
Output is correct |
12 |
Correct |
1 ms |
676 KB |
Output is correct |
13 |
Correct |
6 ms |
5076 KB |
Output is correct |
14 |
Correct |
14 ms |
12700 KB |
Output is correct |
15 |
Correct |
6 ms |
5332 KB |
Output is correct |
16 |
Correct |
15 ms |
12876 KB |
Output is correct |
17 |
Correct |
13 ms |
10844 KB |
Output is correct |
18 |
Correct |
21 ms |
20928 KB |
Output is correct |
19 |
Correct |
2 ms |
1620 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
5444 KB |
Output is correct |
22 |
Correct |
7 ms |
7124 KB |
Output is correct |
23 |
Correct |
6 ms |
5544 KB |
Output is correct |
24 |
Correct |
16 ms |
13428 KB |
Output is correct |
25 |
Correct |
35 ms |
24476 KB |
Output is correct |
26 |
Correct |
31 ms |
21580 KB |
Output is correct |
27 |
Correct |
2 ms |
1836 KB |
Output is correct |
28 |
Correct |
8 ms |
7340 KB |
Output is correct |
29 |
Correct |
18 ms |
2180 KB |
Output is correct |
30 |
Correct |
18 ms |
7556 KB |
Output is correct |
31 |
Correct |
77 ms |
16352 KB |
Output is correct |
32 |
Correct |
44 ms |
14004 KB |
Output is correct |
33 |
Correct |
80 ms |
25164 KB |
Output is correct |
34 |
Correct |
12 ms |
3188 KB |
Output is correct |
35 |
Correct |
4 ms |
2132 KB |
Output is correct |
36 |
Correct |
38 ms |
3492 KB |
Output is correct |
37 |
Correct |
195 ms |
36496 KB |
Output is correct |
38 |
Correct |
1542 ms |
261072 KB |
Output is correct |
39 |
Correct |
176 ms |
17512 KB |
Output is correct |
40 |
Correct |
597 ms |
202988 KB |
Output is correct |
41 |
Correct |
1615 ms |
338000 KB |
Output is correct |
42 |
Correct |
378 ms |
40956 KB |
Output is correct |
43 |
Correct |
262 ms |
95276 KB |
Output is correct |
44 |
Correct |
287 ms |
95184 KB |
Output is correct |