Submission #309829

# Submission time Handle Problem Language Result Execution time Memory
309829 2020-10-04T15:43:54 Z emaborevkovic Stations (IOI20_stations) C++14
100 / 100
1041 ms 1136 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back

const int N = 1005;
vector <int> ls[N];
vector <int> res;
int depth[N], podstablo[N];

int dfs (int x, int d, int p) {
	int suma = 0;
	depth[x] = d;
	for (int i=0;i<ls[x].size();i++) {
		if (ls[x][i] == p) continue;
		suma += dfs(ls[x][i], d+1, x);
	}
	return podstablo[x] = suma+1;
}

void oznaci (int x, int l, int r, int p) {
	if (depth[x] % 2 == 0) {
		res[x] = l;
		l++;
	}
	else {
		res[x] = r;
		r--;
	}
	for (int i=0;i<ls[x].size();i++) {
		if (ls[x][i] == p) continue;
		oznaci(ls[x][i], l, l+podstablo[ls[x][i]]-1, x);
		l += podstablo[ls[x][i]];
	}
}

vector <int> label (int n, int k, vector <int> u, vector <int> v) {
	res.clear();
	for (int i=0;i<n;i++) ls[i].clear();
	res.resize(n);
	for (int i=0;i<n-1;i++) {
		ls[u[i]].pb(v[i]);
		ls[v[i]].pb(u[i]);
	}
	dfs (0, 0, 0);
	oznaci(0, 0, n-1, 0);
	return res;
} 

int find_next_station(int s, int t, vector <int> c) {
	int n = c.size();
	if (s == 0) {
		for (int i=0;i<n;i++) {
			if (c[i] >= t) return c[i];
		}
	}
	if (n == 1) return c[0];
	if (s < c[0]) {
		if (t < s || t > c[n-2]) return c[n-1];
		for (int i=0;i<n-1;i++) {
			if (c[i] >= t) return c[i];
		} 
	}
	if (t < c[1] || t > s) return c[0];
	for (int i=n-1;i>0;i--) {
		if (t >= c[i]) return c[i];
	}
} 

Compilation message

stations.cpp: In function 'int dfs(int, int, int)':
stations.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i=0;i<ls[x].size();i++) {
      |               ~^~~~~~~~~~~~~
stations.cpp: In function 'void oznaci(int, int, int, int)':
stations.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (int i=0;i<ls[x].size();i++) {
      |               ~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 526 ms 1008 KB Output is correct
2 Correct 491 ms 1024 KB Output is correct
3 Correct 981 ms 768 KB Output is correct
4 Correct 675 ms 868 KB Output is correct
5 Correct 690 ms 768 KB Output is correct
6 Correct 509 ms 1024 KB Output is correct
7 Correct 468 ms 1024 KB Output is correct
8 Correct 3 ms 876 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 832 KB Output is correct
2 Correct 607 ms 812 KB Output is correct
3 Correct 899 ms 1032 KB Output is correct
4 Correct 681 ms 768 KB Output is correct
5 Correct 588 ms 912 KB Output is correct
6 Correct 447 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 1088 KB Output is correct
2 Correct 440 ms 1120 KB Output is correct
3 Correct 945 ms 1044 KB Output is correct
4 Correct 661 ms 872 KB Output is correct
5 Correct 601 ms 880 KB Output is correct
6 Correct 535 ms 1024 KB Output is correct
7 Correct 507 ms 1024 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 618 ms 880 KB Output is correct
12 Correct 522 ms 1112 KB Output is correct
13 Correct 496 ms 1008 KB Output is correct
14 Correct 472 ms 896 KB Output is correct
15 Correct 55 ms 868 KB Output is correct
16 Correct 69 ms 768 KB Output is correct
17 Correct 114 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1041 ms 768 KB Output is correct
2 Correct 825 ms 868 KB Output is correct
3 Correct 689 ms 1040 KB Output is correct
4 Correct 3 ms 872 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 623 ms 776 KB Output is correct
8 Correct 989 ms 872 KB Output is correct
9 Correct 756 ms 868 KB Output is correct
10 Correct 627 ms 1008 KB Output is correct
11 Correct 7 ms 864 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 5 ms 868 KB Output is correct
14 Correct 4 ms 872 KB Output is correct
15 Correct 1 ms 868 KB Output is correct
16 Correct 544 ms 768 KB Output is correct
17 Correct 594 ms 768 KB Output is correct
18 Correct 497 ms 1040 KB Output is correct
19 Correct 506 ms 768 KB Output is correct
20 Correct 504 ms 872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 534 ms 1024 KB Output is correct
2 Correct 536 ms 1056 KB Output is correct
3 Correct 934 ms 872 KB Output is correct
4 Correct 679 ms 868 KB Output is correct
5 Correct 594 ms 864 KB Output is correct
6 Correct 452 ms 1024 KB Output is correct
7 Correct 490 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 864 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 504 ms 808 KB Output is correct
12 Correct 533 ms 812 KB Output is correct
13 Correct 1023 ms 864 KB Output is correct
14 Correct 693 ms 768 KB Output is correct
15 Correct 664 ms 868 KB Output is correct
16 Correct 435 ms 820 KB Output is correct
17 Correct 694 ms 868 KB Output is correct
18 Correct 470 ms 1136 KB Output is correct
19 Correct 472 ms 1024 KB Output is correct
20 Correct 506 ms 768 KB Output is correct
21 Correct 68 ms 896 KB Output is correct
22 Correct 93 ms 780 KB Output is correct
23 Correct 104 ms 768 KB Output is correct
24 Correct 7 ms 876 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 4 ms 880 KB Output is correct
28 Correct 2 ms 872 KB Output is correct
29 Correct 617 ms 768 KB Output is correct
30 Correct 610 ms 768 KB Output is correct
31 Correct 532 ms 868 KB Output is correct
32 Correct 572 ms 872 KB Output is correct
33 Correct 606 ms 768 KB Output is correct
34 Correct 376 ms 1024 KB Output is correct
35 Correct 447 ms 1008 KB Output is correct
36 Correct 481 ms 1108 KB Output is correct
37 Correct 466 ms 1024 KB Output is correct
38 Correct 472 ms 1008 KB Output is correct
39 Correct 450 ms 1024 KB Output is correct
40 Correct 474 ms 768 KB Output is correct
41 Correct 503 ms 772 KB Output is correct
42 Correct 76 ms 816 KB Output is correct
43 Correct 114 ms 800 KB Output is correct
44 Correct 158 ms 916 KB Output is correct
45 Correct 186 ms 768 KB Output is correct
46 Correct 333 ms 816 KB Output is correct
47 Correct 331 ms 772 KB Output is correct
48 Correct 79 ms 1024 KB Output is correct
49 Correct 73 ms 1024 KB Output is correct