제출 #397850

#제출 시각아이디문제언어결과실행 시간메모리
397850maomao90Hotspot (NOI17_hotspot)C++14
100 / 100
812 ms1192 KiB
#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
*/

컴파일 시 표준 에러 (stderr) 메시지

hotspot.cpp: In function 'int main()':
hotspot.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
hotspot.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |   int u, v; scanf("%d%d", &u, &v);
      |             ~~~~~^~~~~~~~~~~~~~~~
hotspot.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
hotspot.cpp:22:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...