답안 #872759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872759 2023-11-13T16:57:53 Z rainboy Experimental Charges (NOI19_charges) C
100 / 100
25 ms 2588 KB
#include <stdio.h>
#include <string.h>

#define N	100000

int ds[N * 2];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	int n, q;

	scanf("%d%d", &n, &q);
	memset(ds, -1, n * 2 * sizeof *ds);
	while (q--) {
		static char s[2];
		int i, j;

		scanf("%s%d%d", s, &i, &j), i--, j--;
		if (s[0] == 'A')
			join(i << 1 | 0, j << 1 | 1), join(i << 1 | 1, j << 1 | 0);
		else if (s[0] == 'R')
			join(i << 1 | 0, j << 1 | 0), join(i << 1 | 1, j << 1 | 1);
		else
			if (find(i << 1 | 0) == find(j << 1 | 1))
				printf("A\n");
			else if (find(i << 1 | 0) == find(j << 1 | 0))
				printf("R\n");
			else
				printf("?\n");
	}
	return 0;
}

Compilation message

charges.c: In function 'main':
charges.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
charges.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%s%d%d", s, &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1884 KB Output is correct
2 Correct 15 ms 2044 KB Output is correct
3 Correct 17 ms 2108 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2588 KB Output is correct
2 Correct 17 ms 2388 KB Output is correct
3 Correct 18 ms 2396 KB Output is correct
4 Correct 19 ms 2396 KB Output is correct
5 Correct 19 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2396 KB Output is correct
2 Correct 18 ms 2384 KB Output is correct
3 Correct 18 ms 2420 KB Output is correct
4 Correct 24 ms 2396 KB Output is correct
5 Correct 19 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 1884 KB Output is correct
7 Correct 15 ms 2044 KB Output is correct
8 Correct 17 ms 2108 KB Output is correct
9 Correct 16 ms 2140 KB Output is correct
10 Correct 16 ms 2140 KB Output is correct
11 Correct 25 ms 2588 KB Output is correct
12 Correct 17 ms 2388 KB Output is correct
13 Correct 18 ms 2396 KB Output is correct
14 Correct 19 ms 2396 KB Output is correct
15 Correct 19 ms 2520 KB Output is correct
16 Correct 17 ms 2396 KB Output is correct
17 Correct 18 ms 2384 KB Output is correct
18 Correct 18 ms 2420 KB Output is correct
19 Correct 24 ms 2396 KB Output is correct
20 Correct 19 ms 2396 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 17 ms 2396 KB Output is correct
27 Correct 18 ms 2468 KB Output is correct
28 Correct 21 ms 2284 KB Output is correct
29 Correct 21 ms 2388 KB Output is correct
30 Correct 17 ms 2396 KB Output is correct