#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
vector<int> adj[5005];
int dist[5005][5005],cara[5005][5005],ret[5005];
double byk[5005];
bool flag[5005];
int a[2005],b[2005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N,M,u,v,K;
cin >> N >> M;
for(int i=1;i<=M;i++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=0;i<N;i++){
memset(flag,false,sizeof(flag));
for(int j=0;j<N;j++){
dist[i][j]=INF;
}
cara[i][i]=1;
dist[i][i]=0;
queue<int> Q;
Q.push(i);
while(!Q.empty()){
int s=Q.front();
Q.pop();
for(int j=0;j<adj[s].size();j++){
int t=adj[s][j];
if(!flag[t]){
if(dist[i][t]>dist[i][s]+1){
dist[i][t]=dist[i][s]+1;
cara[i][t]+=cara[i][s];
flag[t]=true;
Q.push(t);
}
}
else{
if(dist[i][s]+1==dist[i][t]){
cara[i][t]+=cara[i][s];
}
}
}
}
}
cin >> K;
for(int i=1;i<=K;i++){
cin >> a[i] >> b[i];
memset(ret,0,sizeof(ret));
for(int j=0;j<N;j++){
if(dist[a[i]][j]+dist[j][b[i]]==dist[a[i]][b[i]]){
ret[j]=(cara[a[i]][j]*cara[j][b[i]]);
byk[j]+=(double)ret[j]/cara[a[i]][b[i]];
}
}
}
double maxi=-1.0;
int ans;
for(int i=0;i<N;i++){
if(byk[i]>maxi){
maxi=byk[i];
ans=i;
}
}
cout << ans << endl;
return 0;
}
Compilation message
hotspot.cpp: In function 'int main()':
hotspot.cpp:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<adj[s].size();j++){
~^~~~~~~~~~~~~~
hotspot.cpp:70:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << ans << endl;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
8 |
Correct |
3 ms |
2944 KB |
Output is correct |
9 |
Correct |
10 ms |
7040 KB |
Output is correct |
10 |
Correct |
21 ms |
12416 KB |
Output is correct |
11 |
Correct |
1 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
3968 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
8 |
Correct |
4 ms |
4096 KB |
Output is correct |
9 |
Correct |
10 ms |
8448 KB |
Output is correct |
10 |
Correct |
9 ms |
7296 KB |
Output is correct |
11 |
Correct |
19 ms |
12800 KB |
Output is correct |
12 |
Correct |
1 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
4 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
8 |
Correct |
3 ms |
2944 KB |
Output is correct |
9 |
Correct |
10 ms |
7040 KB |
Output is correct |
10 |
Correct |
21 ms |
12416 KB |
Output is correct |
11 |
Correct |
1 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
3968 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
4 ms |
4096 KB |
Output is correct |
16 |
Correct |
10 ms |
8448 KB |
Output is correct |
17 |
Correct |
9 ms |
7296 KB |
Output is correct |
18 |
Correct |
19 ms |
12800 KB |
Output is correct |
19 |
Correct |
1 ms |
1664 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
4 ms |
4096 KB |
Output is correct |
22 |
Correct |
7 ms |
5248 KB |
Output is correct |
23 |
Correct |
5 ms |
4224 KB |
Output is correct |
24 |
Correct |
16 ms |
8832 KB |
Output is correct |
25 |
Correct |
27 ms |
14584 KB |
Output is correct |
26 |
Correct |
23 ms |
13056 KB |
Output is correct |
27 |
Correct |
2 ms |
1792 KB |
Output is correct |
28 |
Correct |
7 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
8 |
Correct |
3 ms |
2944 KB |
Output is correct |
9 |
Correct |
10 ms |
7040 KB |
Output is correct |
10 |
Correct |
21 ms |
12416 KB |
Output is correct |
11 |
Correct |
1 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
3968 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
13 ms |
1920 KB |
Output is correct |
16 |
Correct |
17 ms |
5428 KB |
Output is correct |
17 |
Correct |
62 ms |
10488 KB |
Output is correct |
18 |
Correct |
30 ms |
9088 KB |
Output is correct |
19 |
Correct |
75 ms |
14968 KB |
Output is correct |
20 |
Correct |
13 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6784 KB |
Output is correct |
2 |
Correct |
17 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
10752 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
3712 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
8 ms |
6912 KB |
Output is correct |
8 |
Correct |
3 ms |
2944 KB |
Output is correct |
9 |
Correct |
10 ms |
7040 KB |
Output is correct |
10 |
Correct |
21 ms |
12416 KB |
Output is correct |
11 |
Correct |
1 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
3968 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
4 ms |
4096 KB |
Output is correct |
16 |
Correct |
10 ms |
8448 KB |
Output is correct |
17 |
Correct |
9 ms |
7296 KB |
Output is correct |
18 |
Correct |
19 ms |
12800 KB |
Output is correct |
19 |
Correct |
1 ms |
1664 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
4 ms |
4096 KB |
Output is correct |
22 |
Correct |
7 ms |
5248 KB |
Output is correct |
23 |
Correct |
5 ms |
4224 KB |
Output is correct |
24 |
Correct |
16 ms |
8832 KB |
Output is correct |
25 |
Correct |
27 ms |
14584 KB |
Output is correct |
26 |
Correct |
23 ms |
13056 KB |
Output is correct |
27 |
Correct |
2 ms |
1792 KB |
Output is correct |
28 |
Correct |
7 ms |
5376 KB |
Output is correct |
29 |
Correct |
13 ms |
1920 KB |
Output is correct |
30 |
Correct |
17 ms |
5428 KB |
Output is correct |
31 |
Correct |
62 ms |
10488 KB |
Output is correct |
32 |
Correct |
30 ms |
9088 KB |
Output is correct |
33 |
Correct |
75 ms |
14968 KB |
Output is correct |
34 |
Correct |
13 ms |
2816 KB |
Output is correct |
35 |
Correct |
3 ms |
1920 KB |
Output is correct |
36 |
Correct |
36 ms |
2936 KB |
Output is correct |
37 |
Correct |
176 ms |
20668 KB |
Output is correct |
38 |
Correct |
1334 ms |
121764 KB |
Output is correct |
39 |
Correct |
165 ms |
11388 KB |
Output is correct |
40 |
Correct |
528 ms |
96248 KB |
Output is correct |
41 |
Correct |
1426 ms |
154944 KB |
Output is correct |
42 |
Correct |
330 ms |
23288 KB |
Output is correct |
43 |
Correct |
226 ms |
48148 KB |
Output is correct |
44 |
Correct |
222 ms |
48120 KB |
Output is correct |