#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt[5001][5001],d[5001][5001],ans_node,x[2001],y[2001];
vector<int> adj[5001];
queue<int> q;
long double ans;
void bfs(int x) {
memset(d[x],0x3f,sizeof(d[x]));
q.push(x);
d[x][x]=0;
cnt[x][x]=1;
while (!q.empty()) {
int a=q.front();
q.pop();
for (auto s : adj[a]) {
if (d[x][s]>d[x][a]+1) {
d[x][s]=d[x][a]+1;
cnt[x][s]+=cnt[x][a];
q.push(s);
} else if (d[x][s]==d[x][a]+1) cnt[x][s]+=cnt[x][a];
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for (int i=0; i<m; ++i) {
int a,b;
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cin>>k;
for (int i=0; i<k; ++i) cin>>x[i]>>y[i];
for (int i=0; i<n; ++i) bfs(i);
for (int i=0; i<n; ++i) {
long double sum=0;
for (int j=0; j<k; ++j) {
if (d[x[j]][i]+d[i][y[j]]==d[x[j]][y[j]]) {
sum+=(cnt[x[j]][i]*cnt[i][y[j]])/cnt[x[j]][y[j]];
}
}
if (sum>ans) ans_node=i,ans=sum;
}
cout<<ans_node;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
8 |
Correct |
4 ms |
6612 KB |
Output is correct |
9 |
Correct |
12 ms |
14164 KB |
Output is correct |
10 |
Correct |
25 ms |
22512 KB |
Output is correct |
11 |
Correct |
2 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
1348 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
14 ms |
16432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
8 |
Correct |
5 ms |
8660 KB |
Output is correct |
9 |
Correct |
12 ms |
16468 KB |
Output is correct |
10 |
Correct |
11 ms |
14660 KB |
Output is correct |
11 |
Correct |
23 ms |
22848 KB |
Output is correct |
12 |
Correct |
2 ms |
3284 KB |
Output is correct |
13 |
Correct |
1 ms |
1728 KB |
Output is correct |
14 |
Correct |
6 ms |
8896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
8 |
Correct |
4 ms |
6612 KB |
Output is correct |
9 |
Correct |
12 ms |
14164 KB |
Output is correct |
10 |
Correct |
25 ms |
22512 KB |
Output is correct |
11 |
Correct |
2 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
1348 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
14 ms |
16432 KB |
Output is correct |
15 |
Correct |
5 ms |
8660 KB |
Output is correct |
16 |
Correct |
12 ms |
16468 KB |
Output is correct |
17 |
Correct |
11 ms |
14660 KB |
Output is correct |
18 |
Correct |
23 ms |
22848 KB |
Output is correct |
19 |
Correct |
2 ms |
3284 KB |
Output is correct |
20 |
Correct |
1 ms |
1728 KB |
Output is correct |
21 |
Correct |
6 ms |
8896 KB |
Output is correct |
22 |
Correct |
8 ms |
10940 KB |
Output is correct |
23 |
Correct |
8 ms |
9076 KB |
Output is correct |
24 |
Correct |
17 ms |
16960 KB |
Output is correct |
25 |
Correct |
27 ms |
25364 KB |
Output is correct |
26 |
Correct |
23 ms |
23344 KB |
Output is correct |
27 |
Correct |
3 ms |
3668 KB |
Output is correct |
28 |
Correct |
10 ms |
11092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
8 |
Correct |
4 ms |
6612 KB |
Output is correct |
9 |
Correct |
12 ms |
14164 KB |
Output is correct |
10 |
Correct |
25 ms |
22512 KB |
Output is correct |
11 |
Correct |
2 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
1348 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
14 ms |
16432 KB |
Output is correct |
15 |
Correct |
11 ms |
4104 KB |
Output is correct |
16 |
Correct |
17 ms |
11384 KB |
Output is correct |
17 |
Correct |
52 ms |
19404 KB |
Output is correct |
18 |
Correct |
30 ms |
17416 KB |
Output is correct |
19 |
Correct |
79 ms |
25936 KB |
Output is correct |
20 |
Incorrect |
10 ms |
5972 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13764 KB |
Output is correct |
2 |
Correct |
17 ms |
21956 KB |
Output is correct |
3 |
Correct |
16 ms |
20072 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
5 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
6336 KB |
Output is correct |
7 |
Correct |
12 ms |
14036 KB |
Output is correct |
8 |
Correct |
4 ms |
6612 KB |
Output is correct |
9 |
Correct |
12 ms |
14164 KB |
Output is correct |
10 |
Correct |
25 ms |
22512 KB |
Output is correct |
11 |
Correct |
2 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
1348 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
14 ms |
16432 KB |
Output is correct |
15 |
Correct |
5 ms |
8660 KB |
Output is correct |
16 |
Correct |
12 ms |
16468 KB |
Output is correct |
17 |
Correct |
11 ms |
14660 KB |
Output is correct |
18 |
Correct |
23 ms |
22848 KB |
Output is correct |
19 |
Correct |
2 ms |
3284 KB |
Output is correct |
20 |
Correct |
1 ms |
1728 KB |
Output is correct |
21 |
Correct |
6 ms |
8896 KB |
Output is correct |
22 |
Correct |
8 ms |
10940 KB |
Output is correct |
23 |
Correct |
8 ms |
9076 KB |
Output is correct |
24 |
Correct |
17 ms |
16960 KB |
Output is correct |
25 |
Correct |
27 ms |
25364 KB |
Output is correct |
26 |
Correct |
23 ms |
23344 KB |
Output is correct |
27 |
Correct |
3 ms |
3668 KB |
Output is correct |
28 |
Correct |
10 ms |
11092 KB |
Output is correct |
29 |
Correct |
11 ms |
4104 KB |
Output is correct |
30 |
Correct |
17 ms |
11384 KB |
Output is correct |
31 |
Correct |
52 ms |
19404 KB |
Output is correct |
32 |
Correct |
30 ms |
17416 KB |
Output is correct |
33 |
Correct |
79 ms |
25936 KB |
Output is correct |
34 |
Incorrect |
10 ms |
5972 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |