# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397850 | maomao90 | Hotspot (NOI17_hotspot) | C++14 | 812 ms | 1192 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
int n, m, k;
vector <int> adjList[5005];
int dist[5005], dist1[5005], times[5005], times1[5005];
queue <int> bfs;
double e[5005];
int ans = -1;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int u, v; scanf("%d%d", &u, &v);
adjList[u].push_back(v);
adjList[v].push_back(u);
}
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int a, b; scanf("%d%d", &a, &b);
for (int j = 0; j < n; j++) dist[j] = INF, times[j] = 0;
dist[a] = 0, times[a] = 1;
bfs.push(a);
while (!bfs.empty()) {
int u = bfs.front(); bfs.pop();
for (int v : adjList[u]) {
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
times[v] = times[u];
bfs.push(v);
} else if (dist[v] == dist[u] + 1) {
times[v] += times[u];
}
}
}
int nosp = times[b], sp = dist[b];
for (int j = 0; j < n; j++) dist1[j] = INF, times1[j] = 0;
dist1[b] = 0, times1[b] = 1;
bfs.push(b);
while (!bfs.empty()) {
int u = bfs.front(); bfs.pop();
for (int v : adjList[u]) {
if (dist1[v] > dist1[u] + 1) {
dist1[v] = dist1[u] + 1;
times1[v] = times1[u];
bfs.push(v);
} else if (dist1[v] == dist1[u] + 1) {
times1[v] += times1[u];
}
}
}
for (int u = 0; u < n; u++) {
if (dist[u] + dist1[u] == sp) {
e[u] += (double) (times[u] * times1[u]) / nosp;
//printf("%d: %f\n", u, e[u]);
}
}
}
double curmax = -1;
for (int i = 0; i < n; i++) {
if (e[i] > curmax) curmax = e[i], ans = i;
}
printf("%d\n", ans);
return 0;
}
/*
15 19
0 3
1 3
1 4
1 5
2 5
3 6
3 7
4 7
5 7
6 10
7 9
7 10
7 11
8 11
9 12
9 13
10 13
11 13
11 14
2
4 10
3 8
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |