Submission #1073782

# Submission time Handle Problem Language Result Execution time Memory
1073782 2024-08-24T20:55:17 Z allin27x Stations (IOI20_stations) C++17
100 / 100
653 ms 1188 KB
#include <bits/stdc++.h>
using namespace std;
#include "stations.h"

const int N = 1001;
vector<int> adj[N];
int tin[N];
int tout[N];
vector<int> order;

void dfs(int i, int p, int tp) {
	if (!tp) order.push_back(i);
	for (int c: adj[i]) {
		if (c == p) continue;
		dfs(c,i, !tp);
	}
	if (tp) order.push_back(i);
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	order.clear(); for (int i=0; i<n; i++) adj[i].clear();
	std::vector<int> labels(n);
	for (int i=0; i<n-1; i++) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0,0,0);
	for (int i=0; i<n; i++) labels[order[i]] = i;
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if (s > c[0]) {
		// s is time-out, all neighbors are time-in
		// c[0] is the parent
		int n = c.size();
		vector<int> tout(n);
		for (int i=1; i<n-1; i++) {
			tout[i] = c[i+1] - 1;
		}
		tout[n-1] = s - 1;
		for (int i=1; i<n; i++) {
			if (c[i] <= t && t<=tout[i]) return c[i];
		}
		return c[0];
	} else {
		// s is time-in, all neighbors are time-out
		// c[n-1] is the parent
		int n = c.size();
		vector<int> tin(n);
		for (int i=n-2; i>0; i--) {
			tin[i] = c[i-1] + 1;
		}
		tin[0] = s + 1;
		for (int i=0; i<n-1; i++) {
			if (tin[i] <= t && t<=c[i]) return c[i];
		}
		return c[n-1];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 352 ms 684 KB Output is correct
2 Correct 329 ms 684 KB Output is correct
3 Correct 606 ms 684 KB Output is correct
4 Correct 478 ms 684 KB Output is correct
5 Correct 398 ms 684 KB Output is correct
6 Correct 318 ms 940 KB Output is correct
7 Correct 298 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 684 KB Output is correct
2 Correct 369 ms 684 KB Output is correct
3 Correct 592 ms 684 KB Output is correct
4 Correct 454 ms 684 KB Output is correct
5 Correct 432 ms 684 KB Output is correct
6 Correct 339 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 386 ms 684 KB Output is correct
2 Correct 300 ms 684 KB Output is correct
3 Correct 617 ms 684 KB Output is correct
4 Correct 444 ms 684 KB Output is correct
5 Correct 463 ms 684 KB Output is correct
6 Correct 323 ms 684 KB Output is correct
7 Correct 309 ms 684 KB Output is correct
8 Correct 2 ms 776 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 378 ms 684 KB Output is correct
12 Correct 296 ms 1044 KB Output is correct
13 Correct 335 ms 932 KB Output is correct
14 Correct 321 ms 684 KB Output is correct
15 Correct 26 ms 776 KB Output is correct
16 Correct 37 ms 768 KB Output is correct
17 Correct 69 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 653 ms 684 KB Output is correct
2 Correct 456 ms 684 KB Output is correct
3 Correct 418 ms 684 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 430 ms 684 KB Output is correct
8 Correct 607 ms 684 KB Output is correct
9 Correct 484 ms 684 KB Output is correct
10 Correct 394 ms 684 KB Output is correct
11 Correct 4 ms 776 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 333 ms 804 KB Output is correct
17 Correct 354 ms 684 KB Output is correct
18 Correct 381 ms 684 KB Output is correct
19 Correct 350 ms 684 KB Output is correct
20 Correct 347 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 684 KB Output is correct
2 Correct 306 ms 684 KB Output is correct
3 Correct 631 ms 684 KB Output is correct
4 Correct 501 ms 684 KB Output is correct
5 Correct 441 ms 684 KB Output is correct
6 Correct 353 ms 936 KB Output is correct
7 Correct 304 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 299 ms 684 KB Output is correct
12 Correct 377 ms 684 KB Output is correct
13 Correct 621 ms 684 KB Output is correct
14 Correct 512 ms 684 KB Output is correct
15 Correct 421 ms 684 KB Output is correct
16 Correct 296 ms 684 KB Output is correct
17 Correct 419 ms 684 KB Output is correct
18 Correct 299 ms 792 KB Output is correct
19 Correct 349 ms 784 KB Output is correct
20 Correct 278 ms 684 KB Output is correct
21 Correct 26 ms 768 KB Output is correct
22 Correct 42 ms 768 KB Output is correct
23 Correct 61 ms 824 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 776 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 2 ms 764 KB Output is correct
28 Correct 0 ms 764 KB Output is correct
29 Correct 302 ms 684 KB Output is correct
30 Correct 331 ms 684 KB Output is correct
31 Correct 343 ms 684 KB Output is correct
32 Correct 381 ms 684 KB Output is correct
33 Correct 331 ms 684 KB Output is correct
34 Correct 213 ms 684 KB Output is correct
35 Correct 325 ms 1188 KB Output is correct
36 Correct 302 ms 684 KB Output is correct
37 Correct 291 ms 932 KB Output is correct
38 Correct 336 ms 1052 KB Output is correct
39 Correct 276 ms 940 KB Output is correct
40 Correct 335 ms 800 KB Output is correct
41 Correct 320 ms 1056 KB Output is correct
42 Correct 31 ms 768 KB Output is correct
43 Correct 70 ms 728 KB Output is correct
44 Correct 90 ms 688 KB Output is correct
45 Correct 104 ms 736 KB Output is correct
46 Correct 204 ms 860 KB Output is correct
47 Correct 187 ms 684 KB Output is correct
48 Correct 35 ms 960 KB Output is correct
49 Correct 44 ms 1116 KB Output is correct