#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b; a<c; a++)
#define repa(a,b) for(auto a: b)
#define pb push_back
#define ll long long
using namespace std;
const int lim=5e5+5;
vector<int> ady[lim];
int cont[lim]{}, par[lim]{}, lvl[lim]{};
bool vis[lim]{};
void solve(int u, int v){
if(lvl[u]<lvl[v]) swap(u,v);
while(lvl[u]>lvl[v]){
cont[u]++;
u=par[u];
}
while(u!=v){
cont[u]++;
cont[v]++;
u=par[u];
v=par[v];
}
cont[u]++;
}
void dfs(int u, int p){
vis[u]=true;
par[u]=p;
if(p!=-1) lvl[u]=lvl[p]+1;
repa(v,ady[u]) if(!vis[v]) dfs(v,u);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k, u, v;
cin>>n>>m;
rep(i,0,m){
cin>>u>>v;
ady[u].pb(v);
ady[v].pb(u);
}
dfs(0,-1);
cin>>k;
rep(i,0,k){
cin>>u>>v;
if(k>20)solve(u,v);
else{
ll dis[n], dis2[n];
bool vis[n]{}, vis2[n]{};
queue<int> q;
q.push(u);
q.push(0);
vis[u]=true;
while(q.size()){
int x=q.front(), w;
q.pop();
w=q.front();
q.pop();
dis[x]=w;
repa(y,ady[x]){
if(!vis[y]){
vis[y]=true;
q.push(y);
q.push(w+1);
}
}
}
rep(j,0,n){
fill(vis2,vis2+n,0);
q.push(j);
q.push(0);
vis2[j]=true;
while(q.size()){
int x=q.front(), w;
q.pop();
w=q.front();
q.pop();
dis2[x]=w;
repa(y,ady[x]){
if(!vis2[y]){
vis2[y]=true;
q.push(y);
q.push(w+1);
}
}
}
if(dis[v]==dis2[v]+dis[j] && dis[j]<=dis[v]) cont[j]++;
}
}
}
u=0;
rep(i,0,lim) if(cont[u]<cont[i]) u=i;
cout<<u<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
6 ms |
16220 KB |
Output is correct |
9 |
Correct |
8 ms |
16368 KB |
Output is correct |
10 |
Correct |
12 ms |
16216 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16216 KB |
Output is correct |
13 |
Correct |
6 ms |
16304 KB |
Output is correct |
14 |
Correct |
9 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
5 ms |
16220 KB |
Output is correct |
9 |
Correct |
5 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16220 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
7 ms |
16220 KB |
Output is correct |
13 |
Correct |
6 ms |
16216 KB |
Output is correct |
14 |
Correct |
5 ms |
16216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
6 ms |
16220 KB |
Output is correct |
9 |
Correct |
8 ms |
16368 KB |
Output is correct |
10 |
Correct |
12 ms |
16216 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16216 KB |
Output is correct |
13 |
Correct |
6 ms |
16304 KB |
Output is correct |
14 |
Correct |
9 ms |
16220 KB |
Output is correct |
15 |
Correct |
5 ms |
16220 KB |
Output is correct |
16 |
Correct |
5 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16220 KB |
Output is correct |
19 |
Correct |
7 ms |
16220 KB |
Output is correct |
20 |
Correct |
6 ms |
16216 KB |
Output is correct |
21 |
Correct |
5 ms |
16216 KB |
Output is correct |
22 |
Correct |
6 ms |
16220 KB |
Output is correct |
23 |
Correct |
5 ms |
16352 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Correct |
6 ms |
16320 KB |
Output is correct |
26 |
Correct |
5 ms |
16472 KB |
Output is correct |
27 |
Correct |
5 ms |
16220 KB |
Output is correct |
28 |
Correct |
6 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
6 ms |
16220 KB |
Output is correct |
9 |
Correct |
8 ms |
16368 KB |
Output is correct |
10 |
Correct |
12 ms |
16216 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16216 KB |
Output is correct |
13 |
Correct |
6 ms |
16304 KB |
Output is correct |
14 |
Correct |
9 ms |
16220 KB |
Output is correct |
15 |
Correct |
9 ms |
16220 KB |
Output is correct |
16 |
Correct |
11 ms |
16416 KB |
Output is correct |
17 |
Correct |
370 ms |
16728 KB |
Output is correct |
18 |
Incorrect |
216 ms |
16400 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
11 ms |
16216 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
5 ms |
16220 KB |
Output is correct |
5 |
Correct |
6 ms |
16356 KB |
Output is correct |
6 |
Correct |
5 ms |
16356 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
6 ms |
16220 KB |
Output is correct |
9 |
Correct |
8 ms |
16368 KB |
Output is correct |
10 |
Correct |
12 ms |
16216 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16216 KB |
Output is correct |
13 |
Correct |
6 ms |
16304 KB |
Output is correct |
14 |
Correct |
9 ms |
16220 KB |
Output is correct |
15 |
Correct |
5 ms |
16220 KB |
Output is correct |
16 |
Correct |
5 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16220 KB |
Output is correct |
19 |
Correct |
7 ms |
16220 KB |
Output is correct |
20 |
Correct |
6 ms |
16216 KB |
Output is correct |
21 |
Correct |
5 ms |
16216 KB |
Output is correct |
22 |
Correct |
6 ms |
16220 KB |
Output is correct |
23 |
Correct |
5 ms |
16352 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Correct |
6 ms |
16320 KB |
Output is correct |
26 |
Correct |
5 ms |
16472 KB |
Output is correct |
27 |
Correct |
5 ms |
16220 KB |
Output is correct |
28 |
Correct |
6 ms |
16220 KB |
Output is correct |
29 |
Correct |
9 ms |
16220 KB |
Output is correct |
30 |
Correct |
11 ms |
16416 KB |
Output is correct |
31 |
Correct |
370 ms |
16728 KB |
Output is correct |
32 |
Incorrect |
216 ms |
16400 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |