# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1102953 | 2024-10-19T09:18:31 Z | Avocabo | Hotspot (NOI17_hotspot) | C++17 | 583 ms | 7776 KB |
#include <bits/stdc++.h> using namespace std; #define task "TRAINCENTER" #define fi first #define se second #define pii pair <int, int> #define pb push_back #define ll long long #define pip pair <int, pii> #define pli pair <ll, int> #define double long double const int N = 1e5 + 5; const int mod = 1e9 + 7; const ll inf = 1e18 + 7; int myabs(int x) { return x < 0 ? -x : x; } int n, m, k; vector <int> g[N]; long long cnt[2][N], d[2][N]; double ans[N]; void inp() { cin >> n >> m; for (int i=1; i<=m; ++i) { int u, v; cin >> u >> v; u++; v++; g[u].push_back(v); g[v].push_back(u); } cin >> k; } void bfs(int id, int s) { queue <int> q; for (int i=0; i<=n; ++i) d[id][i] = -1, cnt[id][i] = 0; d[id][s] = 0; q.push(s); cnt[id][s] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (d[id][v] == -1) { d[id][v] = d[id][u] + 1; cnt[id][v] = cnt[id][u]; q.push(v); } else if (d[id][v] == d[id][u] + 1) cnt[id][v] += cnt[id][u]; } } } void solve() { while (k--) { int a, b; cin >> a >> b; a++; b++; bfs(0, a); bfs(1, b); double tmp = cnt[0][b]; for (int i=1; i<=n; ++i) if (d[0][i] + d[1][i] == d[0][b]) { double tmp1 = (double)(cnt[0][i] * cnt[1][i]); ans[i] += (tmp1/tmp); } } int res = 0; for (int i=1; i<=n; ++i) if (ans[i] > ans[res]) res = i; cout << res-1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } inp(); solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
8 | Correct | 2 ms | 7248 KB | Output is correct |
9 | Correct | 2 ms | 7248 KB | Output is correct |
10 | Correct | 2 ms | 7248 KB | Output is correct |
11 | Correct | 2 ms | 7248 KB | Output is correct |
12 | Correct | 2 ms | 7248 KB | Output is correct |
13 | Correct | 2 ms | 7420 KB | Output is correct |
14 | Correct | 3 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
8 | Correct | 2 ms | 7248 KB | Output is correct |
9 | Correct | 2 ms | 7248 KB | Output is correct |
10 | Correct | 3 ms | 7248 KB | Output is correct |
11 | Correct | 4 ms | 7248 KB | Output is correct |
12 | Correct | 3 ms | 7248 KB | Output is correct |
13 | Correct | 3 ms | 7248 KB | Output is correct |
14 | Correct | 3 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
8 | Correct | 2 ms | 7248 KB | Output is correct |
9 | Correct | 2 ms | 7248 KB | Output is correct |
10 | Correct | 2 ms | 7248 KB | Output is correct |
11 | Correct | 2 ms | 7248 KB | Output is correct |
12 | Correct | 2 ms | 7248 KB | Output is correct |
13 | Correct | 2 ms | 7420 KB | Output is correct |
14 | Correct | 3 ms | 7248 KB | Output is correct |
15 | Correct | 2 ms | 7248 KB | Output is correct |
16 | Correct | 2 ms | 7248 KB | Output is correct |
17 | Correct | 3 ms | 7248 KB | Output is correct |
18 | Correct | 4 ms | 7248 KB | Output is correct |
19 | Correct | 3 ms | 7248 KB | Output is correct |
20 | Correct | 3 ms | 7248 KB | Output is correct |
21 | Correct | 3 ms | 7248 KB | Output is correct |
22 | Correct | 2 ms | 7248 KB | Output is correct |
23 | Correct | 2 ms | 7248 KB | Output is correct |
24 | Correct | 2 ms | 7248 KB | Output is correct |
25 | Correct | 3 ms | 7248 KB | Output is correct |
26 | Correct | 4 ms | 7248 KB | Output is correct |
27 | Correct | 2 ms | 7248 KB | Output is correct |
28 | Correct | 3 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
8 | Correct | 2 ms | 7248 KB | Output is correct |
9 | Correct | 2 ms | 7248 KB | Output is correct |
10 | Correct | 2 ms | 7248 KB | Output is correct |
11 | Correct | 2 ms | 7248 KB | Output is correct |
12 | Correct | 2 ms | 7248 KB | Output is correct |
13 | Correct | 2 ms | 7420 KB | Output is correct |
14 | Correct | 3 ms | 7248 KB | Output is correct |
15 | Correct | 4 ms | 7248 KB | Output is correct |
16 | Correct | 2 ms | 7248 KB | Output is correct |
17 | Correct | 4 ms | 7248 KB | Output is correct |
18 | Correct | 3 ms | 7248 KB | Output is correct |
19 | Correct | 5 ms | 7248 KB | Output is correct |
20 | Correct | 3 ms | 7248 KB | Output is correct |
21 | Correct | 2 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Correct | 2 ms | 7248 KB | Output is correct |
4 | Correct | 2 ms | 7248 KB | Output is correct |
5 | Correct | 2 ms | 7248 KB | Output is correct |
6 | Correct | 2 ms | 7248 KB | Output is correct |
7 | Correct | 2 ms | 7248 KB | Output is correct |
8 | Correct | 2 ms | 7248 KB | Output is correct |
9 | Correct | 2 ms | 7248 KB | Output is correct |
10 | Correct | 2 ms | 7248 KB | Output is correct |
11 | Correct | 2 ms | 7248 KB | Output is correct |
12 | Correct | 2 ms | 7248 KB | Output is correct |
13 | Correct | 2 ms | 7420 KB | Output is correct |
14 | Correct | 3 ms | 7248 KB | Output is correct |
15 | Correct | 2 ms | 7248 KB | Output is correct |
16 | Correct | 2 ms | 7248 KB | Output is correct |
17 | Correct | 3 ms | 7248 KB | Output is correct |
18 | Correct | 4 ms | 7248 KB | Output is correct |
19 | Correct | 3 ms | 7248 KB | Output is correct |
20 | Correct | 3 ms | 7248 KB | Output is correct |
21 | Correct | 3 ms | 7248 KB | Output is correct |
22 | Correct | 2 ms | 7248 KB | Output is correct |
23 | Correct | 2 ms | 7248 KB | Output is correct |
24 | Correct | 2 ms | 7248 KB | Output is correct |
25 | Correct | 3 ms | 7248 KB | Output is correct |
26 | Correct | 4 ms | 7248 KB | Output is correct |
27 | Correct | 2 ms | 7248 KB | Output is correct |
28 | Correct | 3 ms | 7248 KB | Output is correct |
29 | Correct | 4 ms | 7248 KB | Output is correct |
30 | Correct | 2 ms | 7248 KB | Output is correct |
31 | Correct | 4 ms | 7248 KB | Output is correct |
32 | Correct | 3 ms | 7248 KB | Output is correct |
33 | Correct | 5 ms | 7248 KB | Output is correct |
34 | Correct | 3 ms | 7248 KB | Output is correct |
35 | Correct | 2 ms | 7248 KB | Output is correct |
36 | Correct | 47 ms | 7248 KB | Output is correct |
37 | Correct | 108 ms | 7504 KB | Output is correct |
38 | Correct | 583 ms | 7760 KB | Output is correct |
39 | Correct | 343 ms | 7760 KB | Output is correct |
40 | Correct | 58 ms | 7504 KB | Output is correct |
41 | Correct | 347 ms | 7760 KB | Output is correct |
42 | Correct | 528 ms | 7776 KB | Output is correct |
43 | Correct | 25 ms | 7248 KB | Output is correct |
44 | Correct | 21 ms | 7248 KB | Output is correct |