답안 #587479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587479 2022-07-02T00:41:18 Z NekoRolly Hotspot (NOI17_hotspot) C++17
100 / 100
514 ms 62156 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3+4;
const int inf = 1e9;

int n,m,k;
int dis[N][N],dp[N][N];
vector<int> adj[N];
bool vis[N];
double val[N];

void bfs(int rt,int dis[],int dp[]){ queue<int> d;
	if (vis[rt]) return;
	for (int i=0; i<n; i++) dis[i] = inf;
	dis[rt] = 0, dp[rt] = 1;
	for (d.push(rt); d.size(); d.pop()){ int u = d.front();
		for (int v : adj[u]){
			if (dis[v] == inf){
				dis[v] = dis[u] + 1; d.push(v);
			}
			if (dis[v] == dis[u] + 1) dp[v] += dp[u];
		}
	}
	vis[rt] = 1;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m;

	for (int a,b; m; m--){ cin >> a >> b;
		adj[a].push_back(b), adj[b].push_back(a);
	}

	cin >> k;

	for (int a,b; k; k--){ cin >> a >> b;
		bfs(a, dis[a], dp[a]), bfs(b, dis[b], dp[b]);
		for (int i=0; i<n; i++) if (dis[a][i] + dis[b][i] == dis[a][b])
			val[i] += double(dp[a][i]*dp[b][i])/dp[a][b];
	}

	for (int i=1; i<n; i++) if (val[i] > val[k]) k = i;

	cout << k << "\n";
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 4 ms 2520 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 3 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 4 ms 2520 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 3 ms 2624 KB Output is correct
22 Correct 2 ms 1364 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 4 ms 2644 KB Output is correct
26 Correct 4 ms 2772 KB Output is correct
27 Correct 2 ms 1492 KB Output is correct
28 Correct 4 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 3 ms 960 KB Output is correct
19 Correct 5 ms 1108 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 452 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 4 ms 2520 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 3 ms 2624 KB Output is correct
22 Correct 2 ms 1364 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 4 ms 2644 KB Output is correct
26 Correct 4 ms 2772 KB Output is correct
27 Correct 2 ms 1492 KB Output is correct
28 Correct 4 ms 3028 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 4 ms 1108 KB Output is correct
32 Correct 3 ms 960 KB Output is correct
33 Correct 5 ms 1108 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 23 ms 2612 KB Output is correct
37 Correct 86 ms 14348 KB Output is correct
38 Correct 514 ms 62156 KB Output is correct
39 Correct 113 ms 11084 KB Output is correct
40 Correct 77 ms 15888 KB Output is correct
41 Correct 364 ms 51124 KB Output is correct
42 Correct 221 ms 21496 KB Output is correct
43 Correct 34 ms 8552 KB Output is correct
44 Correct 30 ms 7692 KB Output is correct