답안 #1052043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052043 2024-08-10T11:16:46 Z rainboy The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
2000 ms 11692 KB
#include "incursion.h"
#include <cstdlib>
#include <vector>

using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

namespace A {
	const int N = 45000;

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

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

	void init(vpi ij) {
		n = ij.size() + 1;
		for (int i = 0; i < n; i++)
			ej[i] = (int *) malloc(3 * sizeof *ej[i]), eo[i] = 0;
		for (int h = 0; h < n - 1; h++) {
			int i = ij[h].first - 1, j = ij[h].second - 1;
			append(i, j), append(j, i);
		}
	}

	int cc[N];

	void dfs(int p, int i, int c) {
		cc[i] = c;
		for (int o = eo[i]; o--; ) {
			int j = ej[i][o];
			if (j != p)
				dfs(i, j, (c + 1) % 3);
		}
	}

	void cleanup() {
		for (int i = 0; i < n; i++)
			free(ej[i]);
	}
}

vi mark(vpi ij, int s) {
	A::init(ij), s--;
	A::dfs(-1, s, 0);
	vi cc(A::n);
	for (int i = 0; i < A::n; i++)
		cc[i] = A::cc[i];
	A::cleanup();
	return cc;
}

namespace B {
	const int N = 45000;

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

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

	void init(vpi ij) {
		n = ij.size() + 1;
		for (int i = 0; i < n; i++)
			ej[i] = (int *) malloc(3 * sizeof *ej[i]), eo[i] = 0;
		for (int h = 0; h < n - 1; h++) {
			int i = ij[h].first - 1, j = ij[h].second - 1;
			append(i, j), append(j, i);
		}
	}

	int sz[N];

	void dfs(int p, int i) {
		sz[i] = 1;
		for (int o = eo[i]; o--; ) {
			int j = ej[i][o];
			if (j != p) {
				dfs(i, j);
				sz[i] += sz[j];
			}
		}
	}

	unsigned int Z = 12345;

	int rand_() {
		return (Z *= 3) >> 1;
	}

	void sort(int *ii, int l, int r) {
		while (l < r) {
			int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

			while (j < k)
				if (sz[ii[j]] == sz[i_])
					j++;
				else if (sz[ii[j]] < sz[i_]) {
					tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
					i++, j++;
				} else {
					k--;
					tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
				}
			sort(ii, l, i);
			l = k;
		}
	}

	void cleanup() {
		for (int i = 0; i < n; i++)
			free(ej[i]);
	}
}

void locate(vpi ij, int i, int c) {
	B::init(ij), i--;
	int p = -1;
	while (1) {
		B::dfs(p, i);
		B::sort(B::ej[i], 0, B::eo[i]);
		bool found = false;
		for (int o = B::eo[i]; o--; ) {
			int j = B::ej[i][o];
			if (j != p) {
				if ((visit(j + 1) + 1) % 3 == c) {
					found = true, p = i, i = j, c = (c + 2) % 3;
					break;
				}
				visit(i + 1);
			}
		}
		if (!found)
			break;
	}
	B::cleanup();
}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 768 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3111 ms 11692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 59 ms 6728 KB Partially correct
2 Partially correct 147 ms 6740 KB Partially correct
3 Partially correct 172 ms 6468 KB Partially correct
4 Partially correct 481 ms 8924 KB Partially correct
5 Execution timed out 3109 ms 8932 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 768 KB Partially correct
2 Execution timed out 3111 ms 11692 KB Time limit exceeded
3 Halted 0 ms 0 KB -