답안 #484300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484300 2021-11-02T22:39:24 Z rainboy Magenta (COCI21_magenta) C
30 / 110
38 ms 7908 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000

int ij[N], cc[N];
int *eh[N], eo[N];

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

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

int dd[N];

void dfs(int p, int i, int d) {
	int o;

	dd[i] = d;
	for (o = eo[i]; o--; ) {
		int h = eh[i][o], j = i ^ ij[h];

		if (j != p)
			dfs(i, j, d + 1);
	}
}

int main() {
	int n, u, v, h, i, j;

	scanf("%d%d%d", &n, &u, &v), u--, v--;
	for (i = 0; i < n; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (h = 0; h < n - 1; h++) {
		static char s[8];

		scanf("%d%d%s", &i, &j, s), i--, j--;
		ij[h] = i ^ j, cc[h] = s[0] == 'm' ? 0 : (s[0] == 'b' ? 1 : -1);
		append(i, h), append(j, h);
	}
	dfs(-1, u, 0);
	printf(dd[v] % 2 == 0 ? "Paula\n" : "Marin\n");
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d%d", &n, &u, &v), u--, v--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d%d%s", &i, &j, s), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5976 KB Output is correct
2 Correct 36 ms 7872 KB Output is correct
3 Correct 37 ms 7876 KB Output is correct
4 Correct 36 ms 7792 KB Output is correct
5 Correct 38 ms 7908 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -