#include <iostream>
#include <queue>
#include <vector>
#define pii pair<int,int>
#define ppi pair<int,pii>
#define fst first
#define snd second
#define vi vector<int>
#define pub push_back
using namespace std;
vector<vi> adj;int n,m,k,a,b,cr[5001][2]={},dst[5001]={};bool bt[5001]={};
double lk[5001]={};
queue<ppi> q;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for (int i=0;i<n;i++) {adj.pub(vi());}
for (int i=0;i<m;i++) {cin>>a>>b;adj[a].pub(b);adj[b].pub(a);}
cin>>k;
for (int i=0;i<k;i++)
{
cin>>a>>b;
for (int j=0;j<n;j++) {dst[j] = -1;bt[j]=0;}
q.push({a,{0,-1}});
while (!q.empty())
{
ppi dt = q.front();q.pop();
if (dst[dt.fst]==-1)
{
dst[dt.fst] = dt.snd.fst;
cr[dt.fst][0] = ((dt.snd.snd==-1)?(1):cr[dt.snd.snd][0]);
for (auto v:adj[dt.fst]) {q.push({v,{dt.snd.fst+1,dt.fst}});}
}
else if (dst[dt.fst]==dt.snd.fst) {cr[dt.fst][0]+=((dt.snd.snd==-1)?1:cr[dt.snd.snd][0]);}
//
}
q.push({b,{dst[b],-1}});
while (!q.empty())
{
ppi dt = q.front();q.pop();
cr[dt.fst][1]+=((dt.snd.snd==-1)?1:cr[dt.snd.snd][1]);
if (!bt[dt.fst])
{
bt[dt.fst] = 1;
for (auto v:adj[dt.fst])
{
if (dst[v] == dt.snd.fst-1 && dst[v] >= 0) {q.push({v,{dt.snd.fst-1,dt.fst}});}
}
}
}
//cout<<cr[b][0]<<"\n";
for (int i=0;i<n;i++)
{
//cout<<i<<" "<<cr[i][0]<<" "<<cr[i][1]<<" "<<dst[i]<<"\n";
lk[i] += (double) cr[i][0] * cr[i][1] / cr[b][0];
}
for (int i=0;i<n;i++) {cr[i][0] = cr[i][1] = 0;}
}
int mx = 0;
for (int i=1;i<n;i++)
{
if (lk[i]>lk[mx]) {mx = i;}
//cout<<i<<" "<<lk[i]<<"\n";
}
cout<<mx<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
7 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
3 ms |
572 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
7 ms |
640 KB |
Output is correct |
32 |
Correct |
3 ms |
512 KB |
Output is correct |
33 |
Correct |
6 ms |
640 KB |
Output is correct |
34 |
Correct |
3 ms |
572 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
134 ms |
896 KB |
Output is correct |
37 |
Correct |
319 ms |
896 KB |
Output is correct |
38 |
Correct |
1306 ms |
1656 KB |
Output is correct |
39 |
Correct |
2043 ms |
1948 KB |
Output is correct |
40 |
Correct |
95 ms |
768 KB |
Output is correct |
41 |
Correct |
759 ms |
1680 KB |
Output is correct |
42 |
Correct |
1988 ms |
1992 KB |
Output is correct |
43 |
Correct |
55 ms |
700 KB |
Output is correct |
44 |
Correct |
44 ms |
640 KB |
Output is correct |