답안 #1072278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072278 2024-08-23T16:18:13 Z NeroZein The Ties That Guide Us (CEOI23_incursion) C++17
30 / 100
166 ms 20576 KB
#include <bits/stdc++.h>
#include "incursion.h"
 
using namespace std; 
 
vector<int> mark(vector<pair<int, int>> F, int safe) {
	safe--;
	int n = (int) F.size() + 1;;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; ++i) {
		auto [u, v] = F[i];
		--u, --v;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	vector<int> dist(n); 
	function<void(int, int)> dfs = [&](int v, int p) {
		for (int u : g[v]) {
			if (u != p) {
				dist[u] = dist[v] + 1; 
				dfs(u, v); 
			}
		}
	};
	dfs(safe, safe); 
	vector<int> ties(n); 
	function<void(int, int)> dfs2 = [&](int v, int p) {
		for (int u : g[v]) {
			if (u != p) {
				if (dist[v] < dist[u]) {
					ties[u] = 1; 
				}
				dfs2(u, v); 
			}
		}
	};
	for (int i = 0; i < n; ++i) {
		if (g[i].size() == 2) {
			dfs2(i, i);
			break; 
		}
	}
	return ties; 
}
 
void locate(vector<pair<int, int>> F, int curr, int t) {
	--curr;
	int n = (int) F.size() + 1; 
	vector<vector<int>> g(n); 
	for (int i = 0; i < n - 1; ++i) {
		auto [u, v] = F[i];
		--u, --v; 
		g[u].push_back(v);
		g[v].push_back(u); 
	} 
	vector<int> sz(n);
	vector<int> pr(n, -1);
	function<void(int, int)> dfs = [&](int v, int p) {
		sz[v] = 1;
		for (int u : g[v]) {
			if (u != p) {
				pr[u] = v;
				dfs(u, v);
				sz[v] += sz[u]; 
			}
		}
	};
	for (int i = 0; i < n; ++i) {
		if (g[i].size() == 2) {
			dfs(i, i); 
			break;
		}
	}
	function<void(int, int, int)> dfs2 = [&](int v, int p, int tt) {
		if (tt == 1) {
			assert(pr[v] != p && pr[v] != -1); 
			int x = visit(pr[v] + 1);
			return dfs2(pr[v], v, x);
		}
		sort(g[v].begin(), g[v].end(), [&](int i, int j) {
			return sz[i] > sz[j];
		});
		for (int u : g[v]) {
			if (u == pr[v] || u == p) continue; 
			int x = visit(u + 1);
			if (x == 1) {
				visit(v + 1);
			} else {
				return dfs2(u, v, x); 
			}
		}
	};
	dfs2(curr, curr, t);
}

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 Correct 2 ms 764 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 20576 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 7844 KB Correct
2 Correct 80 ms 7768 KB Correct
3 Correct 81 ms 7768 KB Correct
4 Correct 92 ms 11980 KB Correct
5 Correct 137 ms 11948 KB Correct
6 Correct 166 ms 12108 KB Correct
7 Correct 79 ms 7752 KB Correct
8 Correct 79 ms 7336 KB Correct
9 Correct 78 ms 7812 KB Correct
10 Correct 76 ms 7324 KB Correct
11 Correct 73 ms 7500 KB Correct
12 Correct 73 ms 7328 KB Correct
13 Correct 88 ms 7820 KB Correct
14 Correct 60 ms 5712 KB Correct
15 Correct 61 ms 5808 KB Correct
16 Correct 77 ms 7324 KB Correct
17 Correct 72 ms 7324 KB Correct
18 Correct 81 ms 7668 KB Correct
19 Correct 82 ms 7676 KB Correct
20 Correct 62 ms 5880 KB Correct
21 Correct 51 ms 5892 KB Correct
22 Correct 59 ms 5904 KB Correct
23 Correct 56 ms 5840 KB Correct
24 Correct 59 ms 6300 KB Correct
25 Correct 57 ms 5868 KB Correct
26 Correct 81 ms 7840 KB Correct
27 Correct 84 ms 7764 KB Correct
28 Correct 79 ms 7672 KB Correct
29 Correct 75 ms 7704 KB Correct
30 Correct 77 ms 7812 KB Correct
31 Correct 79 ms 7664 KB Correct
32 Correct 88 ms 7836 KB Correct
33 Correct 91 ms 7536 KB Correct
34 Correct 76 ms 7700 KB Correct
35 Correct 90 ms 7844 KB Correct
36 Correct 79 ms 7888 KB Correct
37 Correct 90 ms 7836 KB Correct
38 Correct 70 ms 7684 KB Correct
39 Correct 83 ms 7580 KB Correct
40 Correct 71 ms 7700 KB Correct
41 Correct 69 ms 7852 KB Correct
42 Correct 79 ms 7844 KB Correct
43 Correct 82 ms 8096 KB Correct
44 Correct 89 ms 7664 KB Correct
45 Correct 82 ms 7772 KB Correct
46 Correct 79 ms 7808 KB Correct
47 Correct 87 ms 7688 KB Correct
48 Correct 84 ms 7840 KB Correct
49 Correct 83 ms 7760 KB Correct
50 Correct 78 ms 7836 KB Correct
51 Correct 78 ms 7772 KB Correct
52 Correct 82 ms 7840 KB Correct
53 Correct 76 ms 7520 KB Correct
54 Correct 83 ms 7768 KB Correct
55 Correct 87 ms 7684 KB Correct
56 Correct 79 ms 7776 KB Correct
57 Correct 76 ms 7756 KB Correct
58 Correct 67 ms 7692 KB Correct
59 Correct 89 ms 7772 KB Correct
60 Correct 79 ms 7684 KB Correct
61 Correct 82 ms 7788 KB Correct
62 Correct 75 ms 7756 KB Correct
63 Correct 75 ms 7836 KB Correct
64 Correct 76 ms 7840 KB Correct
65 Correct 81 ms 7696 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 764 KB Correct
2 Runtime error 104 ms 20576 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -