답안 #745245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745245 2023-05-19T15:42:20 Z rainboy Hotspot (NOI17_hotspot) C
100 / 100
652 ms 1108 KB
#include <stdio.h>
#include <stdlib.h>

#define N	5000
#define M	40000
#define K	2000

int *ej[N], eo[N], n;

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

void bfs(int *dd, int *kk, int s) {
	static int qu[N];
	int cnt, h, i, j, d, o;

	for (i = 0; i < n; i++)
		dd[i] = n;
	cnt = 0;
	dd[s] = 0, kk[s] = 1, qu[cnt++] = s;
	for (h = 0; h < cnt; h++) {
		i = qu[h], d = dd[i] + 1;
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			if (dd[j] > d)
				dd[j] = d, kk[j] = kk[i], qu[cnt++] = j;
			else if (dd[j] == d)
				kk[j] += kk[i];
		}
	}
}

double xx[N];

void solve(int s, int t) {
	static int dds[N], kks[N], ddt[N], kkt[N];
	int i;

	bfs(dds, kks, s), bfs(ddt, kkt, t);
	for (i = 0; i < n; i++)
		if (dds[i] + ddt[i] == dds[t])
			xx[i] += (double) kks[i] * kkt[i] / kks[t];
}

int main() {
	int m, k, h, i, i_, j, s, t;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j);
		append(i, j), append(j, i);
	}
	scanf("%d", &k);
	while (k--) {
		scanf("%d%d", &s, &t);
		solve(s, t);
	}
	i_ = -1;
	for (i = 0; i < n; i++)
		if (i_ == -1 || xx[i_] < xx[i])
			i_ = i;
	printf("%d\n", i_);
	return 0;
}

Compilation message

hotspot.c: In function 'append':
hotspot.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
hotspot.c: In function 'main':
hotspot.c:53:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
hotspot.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d", &i, &j);
      |   ^~~~~~~~~~~~~~~~~~~~~
hotspot.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d", &k);
      |  ^~~~~~~~~~~~~~~
hotspot.c:62:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   scanf("%d%d", &s, &t);
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 284 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 284 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 284 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 284 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 284 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 292 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 284 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 4 ms 428 KB Output is correct
20 Correct 3 ms 432 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 284 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 284 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 284 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 292 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 4 ms 428 KB Output is correct
34 Correct 3 ms 432 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 56 ms 532 KB Output is correct
37 Correct 126 ms 560 KB Output is correct
38 Correct 652 ms 1040 KB Output is correct
39 Correct 434 ms 1100 KB Output is correct
40 Correct 65 ms 596 KB Output is correct
41 Correct 371 ms 1064 KB Output is correct
42 Correct 539 ms 1108 KB Output is correct
43 Correct 31 ms 552 KB Output is correct
44 Correct 26 ms 572 KB Output is correct