Submission #342403

# Submission time Handle Problem Language Result Execution time Memory
342403 2021-01-02T05:27:16 Z Ta180m Stations (IOI20_stations) C++17
100 / 100
932 ms 1464 KB
#include "stations.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1e3+5;

int cnt, in[MX], out[MX];
vector<int> labels, G[MX];

void dfs(int u, int p, int d) {
	in[u] = cnt++;
	for (int v : G[u]) if (v != p) dfs(v, u, d+1);
	out[u] = cnt++;
	labels[u] = (d%2 == 0 ? in[u] : out[u]);
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for (int i = 0; i < n; ++i) G[i].clear();
	for (int i = 0; i < n-1; ++i)
		G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
	labels.resize(n, 0);
	cnt = 0;
	dfs(0, -1, 0);

	/*for (int i = 0; i < n; ++i) {
		cout << in[i] << ' ' << out[i] << '\n';
	}*/

	// for (int x : labels) cout << x << '\n';
	
	vector<int> tmp(begin(labels), end(labels));
	sort(begin(tmp), end(tmp));
	for (int i = 0; i < labels.size(); ++i)
		labels[i] = lower_bound(begin(tmp), end(tmp), labels[i])-begin(tmp);
	// for (int x : labels) cout << x << '\n';
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) return c[0];
	// unordered_map<int, int> in, out;
	int m = *min_element(begin(c), end(c));
	if (s < m) {
		// in[s] = s;
		// for (int i = 0; i < c.size(); ++i) out[c[i]] = c[i];
		if (s == 0) {
			// s is root
			for (int i = 0; i < c.size(); ++i) {
				if (t <= c[i]) return c[i];
			}
		}
		else {
			int p = *max_element(begin(c), end(c));
			c.erase(find(begin(c), end(c), p));
			if (t < s) return p;
			for (int i = 0; i < c.size(); ++i) {
				if (t <= c[i]) return c[i];
			}
			// in[c[0]] = in[s]+1;
			// for (int i = 1; i < c.size(); ++i) in[c[i]] = out[c[i-1]]+1;
			// out[s] = out[c.back()]+1;
			/*for (int i = 0; i < c.size(); ++i) {
				if (t > in[c[i]] && t <= out[c[i]]) return c[i];
			}*/
			return p;
		}
	}
	else {
		// out[s] = s;
		// for (int i = 0; i < c.size(); ++i) in[c[i]] = c[i];
		int p = m;
		c.erase(find(begin(c), end(c), p));
		if (t > s) return p;
		for (int i = c.size()-1; i >= 0; --i) {
			if (t >= c[i]) return c[i];
		}
		// in[s] = in[c[0]]-1;
		// for (int i = 0; i < c.size()-1; ++i) out[c[i]] = in[c[i+1]]-1;
		// out[c.back()] = out[s]-1;
		/* for (int i = 0; i < c.size(); ++i) {
			if (t > in[c[i]] && t <= out[c[i]]) return c[i];
		}*/
		return p;
	}
	// cout << s << ' ' << t;
	// for (int x : c) cout << ' ' << x;
	// cout << '\n';
	// return c.back();
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0; i < labels.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |    for (int i = 0; i < c.size(); ++i) {
      |                    ~~^~~~~~~~~~
stations.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for (int i = 0; i < c.size(); ++i) {
      |                    ~~^~~~~~~~~~
stations.cpp:92:1: warning: control reaches end of non-void function [-Wreturn-type]
   92 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 544 ms 992 KB Output is correct
2 Correct 439 ms 1056 KB Output is correct
3 Correct 905 ms 1108 KB Output is correct
4 Correct 647 ms 952 KB Output is correct
5 Correct 572 ms 984 KB Output is correct
6 Correct 472 ms 1200 KB Output is correct
7 Correct 433 ms 992 KB Output is correct
8 Correct 3 ms 864 KB Output is correct
9 Correct 4 ms 944 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 896 KB Output is correct
2 Correct 516 ms 880 KB Output is correct
3 Correct 836 ms 992 KB Output is correct
4 Correct 645 ms 1120 KB Output is correct
5 Correct 619 ms 944 KB Output is correct
6 Correct 440 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 1064 KB Output is correct
2 Correct 443 ms 1056 KB Output is correct
3 Correct 849 ms 976 KB Output is correct
4 Correct 684 ms 1108 KB Output is correct
5 Correct 589 ms 864 KB Output is correct
6 Correct 444 ms 1280 KB Output is correct
7 Correct 459 ms 992 KB Output is correct
8 Correct 3 ms 864 KB Output is correct
9 Correct 4 ms 776 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
11 Correct 567 ms 736 KB Output is correct
12 Correct 454 ms 1132 KB Output is correct
13 Correct 495 ms 1148 KB Output is correct
14 Correct 419 ms 864 KB Output is correct
15 Correct 58 ms 984 KB Output is correct
16 Correct 67 ms 736 KB Output is correct
17 Correct 94 ms 872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 913 ms 864 KB Output is correct
2 Correct 653 ms 944 KB Output is correct
3 Correct 592 ms 864 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 4 ms 944 KB Output is correct
6 Correct 2 ms 864 KB Output is correct
7 Correct 604 ms 896 KB Output is correct
8 Correct 886 ms 944 KB Output is correct
9 Correct 685 ms 944 KB Output is correct
10 Correct 600 ms 944 KB Output is correct
11 Correct 4 ms 904 KB Output is correct
12 Correct 6 ms 736 KB Output is correct
13 Correct 5 ms 864 KB Output is correct
14 Correct 4 ms 868 KB Output is correct
15 Correct 1 ms 736 KB Output is correct
16 Correct 523 ms 864 KB Output is correct
17 Correct 499 ms 864 KB Output is correct
18 Correct 519 ms 864 KB Output is correct
19 Correct 540 ms 944 KB Output is correct
20 Correct 584 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 597 ms 944 KB Output is correct
2 Correct 475 ms 992 KB Output is correct
3 Correct 932 ms 944 KB Output is correct
4 Correct 713 ms 1108 KB Output is correct
5 Correct 677 ms 992 KB Output is correct
6 Correct 427 ms 992 KB Output is correct
7 Correct 452 ms 1104 KB Output is correct
8 Correct 3 ms 864 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
11 Correct 439 ms 736 KB Output is correct
12 Correct 526 ms 1200 KB Output is correct
13 Correct 915 ms 944 KB Output is correct
14 Correct 709 ms 944 KB Output is correct
15 Correct 608 ms 1080 KB Output is correct
16 Correct 541 ms 736 KB Output is correct
17 Correct 652 ms 1012 KB Output is correct
18 Correct 547 ms 1216 KB Output is correct
19 Correct 533 ms 1120 KB Output is correct
20 Correct 545 ms 864 KB Output is correct
21 Correct 63 ms 936 KB Output is correct
22 Correct 84 ms 736 KB Output is correct
23 Correct 126 ms 880 KB Output is correct
24 Correct 7 ms 736 KB Output is correct
25 Correct 6 ms 952 KB Output is correct
26 Correct 6 ms 992 KB Output is correct
27 Correct 5 ms 944 KB Output is correct
28 Correct 2 ms 864 KB Output is correct
29 Correct 502 ms 736 KB Output is correct
30 Correct 546 ms 944 KB Output is correct
31 Correct 532 ms 944 KB Output is correct
32 Correct 516 ms 1072 KB Output is correct
33 Correct 533 ms 964 KB Output is correct
34 Correct 321 ms 864 KB Output is correct
35 Correct 528 ms 992 KB Output is correct
36 Correct 528 ms 992 KB Output is correct
37 Correct 464 ms 1120 KB Output is correct
38 Correct 444 ms 1248 KB Output is correct
39 Correct 505 ms 1464 KB Output is correct
40 Correct 565 ms 1376 KB Output is correct
41 Correct 481 ms 1408 KB Output is correct
42 Correct 61 ms 888 KB Output is correct
43 Correct 122 ms 864 KB Output is correct
44 Correct 122 ms 992 KB Output is correct
45 Correct 207 ms 1104 KB Output is correct
46 Correct 286 ms 896 KB Output is correct
47 Correct 252 ms 1104 KB Output is correct
48 Correct 55 ms 1080 KB Output is correct
49 Correct 52 ms 864 KB Output is correct