Submission #949940

# Submission time Handle Problem Language Result Execution time Memory
949940 2024-03-19T23:39:04 Z Saul0906 Hotspot (NOI17_hotspot) C++14
38 / 100
622 ms 16464 KB
#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;
			int 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]) 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 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
8 Correct 6 ms 16220 KB Output is correct
9 Correct 8 ms 16312 KB Output is correct
10 Correct 12 ms 16216 KB Output is correct
11 Correct 6 ms 16220 KB Output is correct
12 Correct 6 ms 16196 KB Output is correct
13 Correct 6 ms 16220 KB Output is correct
14 Correct 9 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
8 Correct 38 ms 16332 KB Output is correct
9 Correct 135 ms 16352 KB Output is correct
10 Correct 125 ms 16356 KB Output is correct
11 Correct 340 ms 16220 KB Output is correct
12 Correct 13 ms 16216 KB Output is correct
13 Correct 8 ms 16220 KB Output is correct
14 Correct 137 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
8 Correct 6 ms 16220 KB Output is correct
9 Correct 8 ms 16312 KB Output is correct
10 Correct 12 ms 16216 KB Output is correct
11 Correct 6 ms 16220 KB Output is correct
12 Correct 6 ms 16196 KB Output is correct
13 Correct 6 ms 16220 KB Output is correct
14 Correct 9 ms 16220 KB Output is correct
15 Correct 38 ms 16332 KB Output is correct
16 Correct 135 ms 16352 KB Output is correct
17 Correct 125 ms 16356 KB Output is correct
18 Correct 340 ms 16220 KB Output is correct
19 Correct 13 ms 16216 KB Output is correct
20 Correct 8 ms 16220 KB Output is correct
21 Correct 137 ms 16220 KB Output is correct
22 Correct 74 ms 16220 KB Output is correct
23 Correct 60 ms 16332 KB Output is correct
24 Correct 250 ms 16352 KB Output is correct
25 Correct 622 ms 16364 KB Output is correct
26 Correct 595 ms 16464 KB Output is correct
27 Correct 27 ms 16216 KB Output is correct
28 Correct 249 ms 16340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
8 Correct 6 ms 16220 KB Output is correct
9 Correct 8 ms 16312 KB Output is correct
10 Correct 12 ms 16216 KB Output is correct
11 Correct 6 ms 16220 KB Output is correct
12 Correct 6 ms 16196 KB Output is correct
13 Correct 6 ms 16220 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 16220 KB Output is correct
17 Correct 358 ms 16308 KB Output is correct
18 Incorrect 206 ms 16400 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16216 KB Output is correct
2 Correct 9 ms 16220 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 16216 KB Output is correct
6 Correct 5 ms 16220 KB Output is correct
7 Correct 9 ms 16368 KB Output is correct
8 Correct 6 ms 16220 KB Output is correct
9 Correct 8 ms 16312 KB Output is correct
10 Correct 12 ms 16216 KB Output is correct
11 Correct 6 ms 16220 KB Output is correct
12 Correct 6 ms 16196 KB Output is correct
13 Correct 6 ms 16220 KB Output is correct
14 Correct 9 ms 16220 KB Output is correct
15 Correct 38 ms 16332 KB Output is correct
16 Correct 135 ms 16352 KB Output is correct
17 Correct 125 ms 16356 KB Output is correct
18 Correct 340 ms 16220 KB Output is correct
19 Correct 13 ms 16216 KB Output is correct
20 Correct 8 ms 16220 KB Output is correct
21 Correct 137 ms 16220 KB Output is correct
22 Correct 74 ms 16220 KB Output is correct
23 Correct 60 ms 16332 KB Output is correct
24 Correct 250 ms 16352 KB Output is correct
25 Correct 622 ms 16364 KB Output is correct
26 Correct 595 ms 16464 KB Output is correct
27 Correct 27 ms 16216 KB Output is correct
28 Correct 249 ms 16340 KB Output is correct
29 Correct 9 ms 16220 KB Output is correct
30 Correct 11 ms 16220 KB Output is correct
31 Correct 358 ms 16308 KB Output is correct
32 Incorrect 206 ms 16400 KB Output isn't correct
33 Halted 0 ms 0 KB -