답안 #457947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
457947 2021-08-07T15:33:05 Z rainboy 기지국 (IOI20_stations) C++17
컴파일 오류
0 ms 0 KB
#include "stations.h"
#include <stdlib.h>
#include <vector>

using namespace std;
typedef vector<int> vi;

const int N = 1000;

int *ej[N], eo[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;
}

int ta[N], tb[N];

void dfs(int p, int i) {
	static int time;
	int o;

	ta[i] = time++;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p)
			dfs(i, j);
	}
	tb[i] = time - 1;
}

vi label(int n, int k, vi uu, vi vv) {
	int h, i;
	vi labels(n);

	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < n - 1; h++)
		append(uu[h], vv[h]), append(vv[h], uu[h]);
	dfs(-1, 0);
	for (i = 0; i < n; i++)
		labels[i] = ta[i] * N + tb[i];
	for (i = 0; i < n; i++)
		printf("%d %d\n", ta[i], tb[i]);
	return labels;
}

int find_next_station(int s, int t, vi cc) {
	int m = cc.size(), h;

	for (h = 0; h < m; h++)
		if (cc[h] / N <= t && t <= cc[h] % N)
			return cc[h];
	return -1;
}

Compilation message

stations.cpp: In function 'void append(int, int)':
stations.cpp:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
stations.cpp: In function 'vi label(int, int, vi, vi)':
stations.cpp:48:3: error: 'printf' was not declared in this scope
   48 |   printf("%d %d\n", ta[i], tb[i]);
      |   ^~~~~~
stations.cpp:3:1: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
    2 | #include <stdlib.h>
  +++ |+#include <cstdio>
    3 | #include <vector>