답안 #742890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742890 2023-05-17T05:38:27 Z hmm789 Drawing (CEOI22_drawing) C++14
100 / 100
219 ms 36964 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> adj[200000];
vector<int> topo;

void dfs(int x, int p) {
	for(int i : adj[x]) if(i != p) {
		dfs(i, x);
	}
	topo.push_back(x);
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, x, y;
	cin >> n;
	for(int i = 0; i < n-1; i++) {
		cin >> x >> y;
		x--; y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(0, -1);
	reverse(topo.begin(), topo.end());
	pair<pair<int, int>, int> pt[n];
	int ans[n];
	for(int i = 0; i < n; i++) {
		cin >> pt[i].first.first >> pt[i].first.second;
		pt[i].second = i;
	}
	sort(pt, pt+n);
	vector<pair<pair<int, int>, int>> top, bottom;
	top.push_back(pt[0]);
	bottom.push_back(pt[0]);
	int idx = -1;
	for(int i = 1; i < n; i++) {
		if(pt[i].first.second < bottom.back().first.second) bottom.push_back(pt[i]);
		else if(pt[i].first.second > top.back().first.second) top.push_back(pt[i]);
		else {
			idx = i;
			break;
		}
	}
	for(int i = idx; i < n; i++) {
		if(abs(pt[i].first.second-bottom.back().first.second) < abs(pt[i].first.second-top.back().first.second)) bottom.push_back(pt[i]);
		else top.push_back(pt[i]);
	}
	for(int i = 0; i < n; i++) {
		if(i < top.size()) {
			ans[top[i].second] = topo[i];
		} else {
			ans[bottom[bottom.size()-1-(i-top.size())].second] = topo[i];
		}
	}
	for(int i = 0; i < n; i++) cout << ans[i]+1 << " ";
}
	

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:52:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   if(i < top.size()) {
      |      ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 21028 KB Output is correct
2 Correct 107 ms 21712 KB Output is correct
3 Correct 98 ms 22284 KB Output is correct
4 Correct 106 ms 22816 KB Output is correct
5 Correct 93 ms 21780 KB Output is correct
6 Correct 93 ms 22288 KB Output is correct
7 Correct 92 ms 21180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5564 KB Output is correct
2 Correct 5 ms 5668 KB Output is correct
3 Correct 6 ms 5588 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 6 ms 5588 KB Output is correct
6 Correct 5 ms 5588 KB Output is correct
7 Correct 5 ms 5572 KB Output is correct
8 Correct 6 ms 5588 KB Output is correct
9 Correct 5 ms 5588 KB Output is correct
10 Correct 7 ms 5672 KB Output is correct
11 Correct 6 ms 5588 KB Output is correct
12 Correct 5 ms 5540 KB Output is correct
13 Correct 5 ms 5688 KB Output is correct
14 Correct 6 ms 5588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5564 KB Output is correct
2 Correct 5 ms 5668 KB Output is correct
3 Correct 6 ms 5588 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 6 ms 5588 KB Output is correct
6 Correct 5 ms 5588 KB Output is correct
7 Correct 5 ms 5572 KB Output is correct
8 Correct 6 ms 5588 KB Output is correct
9 Correct 5 ms 5588 KB Output is correct
10 Correct 7 ms 5672 KB Output is correct
11 Correct 6 ms 5588 KB Output is correct
12 Correct 5 ms 5540 KB Output is correct
13 Correct 5 ms 5688 KB Output is correct
14 Correct 6 ms 5588 KB Output is correct
15 Correct 9 ms 6608 KB Output is correct
16 Correct 9 ms 6568 KB Output is correct
17 Correct 10 ms 6564 KB Output is correct
18 Correct 10 ms 6612 KB Output is correct
19 Correct 10 ms 6580 KB Output is correct
20 Correct 9 ms 6692 KB Output is correct
21 Correct 9 ms 6412 KB Output is correct
22 Correct 9 ms 6612 KB Output is correct
23 Correct 10 ms 6628 KB Output is correct
24 Correct 11 ms 6496 KB Output is correct
25 Correct 10 ms 6604 KB Output is correct
26 Correct 8 ms 6428 KB Output is correct
27 Correct 9 ms 6676 KB Output is correct
28 Correct 9 ms 6440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5564 KB Output is correct
2 Correct 5 ms 5668 KB Output is correct
3 Correct 6 ms 5588 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 6 ms 5588 KB Output is correct
6 Correct 5 ms 5588 KB Output is correct
7 Correct 5 ms 5572 KB Output is correct
8 Correct 6 ms 5588 KB Output is correct
9 Correct 5 ms 5588 KB Output is correct
10 Correct 7 ms 5672 KB Output is correct
11 Correct 6 ms 5588 KB Output is correct
12 Correct 5 ms 5540 KB Output is correct
13 Correct 5 ms 5688 KB Output is correct
14 Correct 6 ms 5588 KB Output is correct
15 Correct 9 ms 6608 KB Output is correct
16 Correct 9 ms 6568 KB Output is correct
17 Correct 10 ms 6564 KB Output is correct
18 Correct 10 ms 6612 KB Output is correct
19 Correct 10 ms 6580 KB Output is correct
20 Correct 9 ms 6692 KB Output is correct
21 Correct 9 ms 6412 KB Output is correct
22 Correct 9 ms 6612 KB Output is correct
23 Correct 10 ms 6628 KB Output is correct
24 Correct 11 ms 6496 KB Output is correct
25 Correct 10 ms 6604 KB Output is correct
26 Correct 8 ms 6428 KB Output is correct
27 Correct 9 ms 6676 KB Output is correct
28 Correct 9 ms 6440 KB Output is correct
29 Correct 61 ms 17336 KB Output is correct
30 Correct 63 ms 17572 KB Output is correct
31 Correct 62 ms 17824 KB Output is correct
32 Correct 61 ms 17156 KB Output is correct
33 Correct 61 ms 16968 KB Output is correct
34 Correct 62 ms 17652 KB Output is correct
35 Correct 62 ms 16560 KB Output is correct
36 Correct 52 ms 16376 KB Output is correct
37 Correct 65 ms 17080 KB Output is correct
38 Correct 62 ms 18116 KB Output is correct
39 Correct 68 ms 15704 KB Output is correct
40 Correct 59 ms 16320 KB Output is correct
41 Correct 58 ms 16728 KB Output is correct
42 Correct 60 ms 15760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 21028 KB Output is correct
2 Correct 107 ms 21712 KB Output is correct
3 Correct 98 ms 22284 KB Output is correct
4 Correct 106 ms 22816 KB Output is correct
5 Correct 93 ms 21780 KB Output is correct
6 Correct 93 ms 22288 KB Output is correct
7 Correct 92 ms 21180 KB Output is correct
8 Correct 6 ms 5564 KB Output is correct
9 Correct 5 ms 5668 KB Output is correct
10 Correct 6 ms 5588 KB Output is correct
11 Correct 5 ms 5588 KB Output is correct
12 Correct 6 ms 5588 KB Output is correct
13 Correct 5 ms 5588 KB Output is correct
14 Correct 5 ms 5572 KB Output is correct
15 Correct 6 ms 5588 KB Output is correct
16 Correct 5 ms 5588 KB Output is correct
17 Correct 7 ms 5672 KB Output is correct
18 Correct 6 ms 5588 KB Output is correct
19 Correct 5 ms 5540 KB Output is correct
20 Correct 5 ms 5688 KB Output is correct
21 Correct 6 ms 5588 KB Output is correct
22 Correct 9 ms 6608 KB Output is correct
23 Correct 9 ms 6568 KB Output is correct
24 Correct 10 ms 6564 KB Output is correct
25 Correct 10 ms 6612 KB Output is correct
26 Correct 10 ms 6580 KB Output is correct
27 Correct 9 ms 6692 KB Output is correct
28 Correct 9 ms 6412 KB Output is correct
29 Correct 9 ms 6612 KB Output is correct
30 Correct 10 ms 6628 KB Output is correct
31 Correct 11 ms 6496 KB Output is correct
32 Correct 10 ms 6604 KB Output is correct
33 Correct 8 ms 6428 KB Output is correct
34 Correct 9 ms 6676 KB Output is correct
35 Correct 9 ms 6440 KB Output is correct
36 Correct 61 ms 17336 KB Output is correct
37 Correct 63 ms 17572 KB Output is correct
38 Correct 62 ms 17824 KB Output is correct
39 Correct 61 ms 17156 KB Output is correct
40 Correct 61 ms 16968 KB Output is correct
41 Correct 62 ms 17652 KB Output is correct
42 Correct 62 ms 16560 KB Output is correct
43 Correct 52 ms 16376 KB Output is correct
44 Correct 65 ms 17080 KB Output is correct
45 Correct 62 ms 18116 KB Output is correct
46 Correct 68 ms 15704 KB Output is correct
47 Correct 59 ms 16320 KB Output is correct
48 Correct 58 ms 16728 KB Output is correct
49 Correct 60 ms 15760 KB Output is correct
50 Correct 103 ms 22664 KB Output is correct
51 Correct 205 ms 35700 KB Output is correct
52 Correct 191 ms 36428 KB Output is correct
53 Correct 197 ms 33300 KB Output is correct
54 Correct 204 ms 36964 KB Output is correct
55 Correct 180 ms 36412 KB Output is correct
56 Correct 190 ms 31616 KB Output is correct
57 Correct 33 ms 11584 KB Output is correct
58 Correct 204 ms 32708 KB Output is correct
59 Correct 183 ms 35608 KB Output is correct
60 Correct 193 ms 36444 KB Output is correct
61 Correct 219 ms 33332 KB Output is correct
62 Correct 35 ms 11712 KB Output is correct
63 Correct 201 ms 34100 KB Output is correct