Submission #314056

# Submission time Handle Problem Language Result Execution time Memory
314056 2020-10-18T02:17:30 Z dlwocks31 Stations (IOI20_stations) C++17
100 / 100
994 ms 1128 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int lbl[1000], cnt;
void dfs(int i, int p, int d, vector<vector<int>> &adj) {
	if(d % 2 == 0)
		lbl[i] = cnt++;
	for(int a: adj[i]) {
		if(a == p) continue;
		dfs(a, i, d+1, adj);
	}
	if(d % 2 == 1)
		lbl[i] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	cnt = 0;
	memset(lbl, 0, sizeof lbl);
	vector<int> labels(n);
	vector<vector<int>> adj(n);
	for(int i=0; i<u.size(); i++) {
		//printf("edge = %d, %d\n", u[i], v[i]);
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0, -1, 0, adj);
	for(int i=0; i<n; i++) {
		//printf("label %d = %d\n", i, lbl[i]);
		labels[i] = lbl[i];
	}
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if(c[0] < s) { // s is out
		reverse(c.begin(), c.end());
	}
	c.insert(c.begin(), s);
	for(int i=1; i<c.size(); i++) {
		//printf("compare between %d, %d\n", c[i-1], c[i]);
		if((c[i-1] <= t && t <= c[i]) || (c[i] <= t && t <= c[i-1])) {
			return c[i];
		}
	}
	return c.back();
}

// int main() {
// 	int s, t, w;
// 	cin >> s >> t >> w;
// 	vector<int> c(w);
// 	for(int i=0; i<w; i++) {
// 		cin >> c[i];
// 	}
// 	cout << find_next_station(s, t, c);
// }

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0; i<u.size(); i++) {
      |               ~^~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=1; i<c.size(); i++) {
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 645 ms 1120 KB Output is correct
2 Correct 525 ms 1024 KB Output is correct
3 Correct 994 ms 640 KB Output is correct
4 Correct 784 ms 640 KB Output is correct
5 Correct 661 ms 644 KB Output is correct
6 Correct 498 ms 1028 KB Output is correct
7 Correct 451 ms 772 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 652 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 768 KB Output is correct
2 Correct 590 ms 824 KB Output is correct
3 Correct 952 ms 644 KB Output is correct
4 Correct 762 ms 640 KB Output is correct
5 Correct 646 ms 640 KB Output is correct
6 Correct 481 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 545 ms 1024 KB Output is correct
2 Correct 555 ms 1008 KB Output is correct
3 Correct 936 ms 640 KB Output is correct
4 Correct 835 ms 672 KB Output is correct
5 Correct 630 ms 640 KB Output is correct
6 Correct 462 ms 1024 KB Output is correct
7 Correct 430 ms 772 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 5 ms 648 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 628 ms 644 KB Output is correct
12 Correct 454 ms 1128 KB Output is correct
13 Correct 456 ms 1024 KB Output is correct
14 Correct 485 ms 768 KB Output is correct
15 Correct 55 ms 900 KB Output is correct
16 Correct 67 ms 856 KB Output is correct
17 Correct 113 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 868 ms 640 KB Output is correct
2 Correct 658 ms 784 KB Output is correct
3 Correct 603 ms 784 KB Output is correct
4 Correct 3 ms 900 KB Output is correct
5 Correct 4 ms 892 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 599 ms 644 KB Output is correct
8 Correct 883 ms 644 KB Output is correct
9 Correct 690 ms 640 KB Output is correct
10 Correct 604 ms 776 KB Output is correct
11 Correct 6 ms 652 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 526 ms 640 KB Output is correct
17 Correct 504 ms 640 KB Output is correct
18 Correct 507 ms 640 KB Output is correct
19 Correct 520 ms 892 KB Output is correct
20 Correct 515 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 524 ms 1008 KB Output is correct
2 Correct 447 ms 1024 KB Output is correct
3 Correct 882 ms 640 KB Output is correct
4 Correct 737 ms 768 KB Output is correct
5 Correct 643 ms 640 KB Output is correct
6 Correct 473 ms 1024 KB Output is correct
7 Correct 529 ms 768 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 5 ms 648 KB Output is correct
10 Correct 1 ms 644 KB Output is correct
11 Correct 607 ms 768 KB Output is correct
12 Correct 565 ms 760 KB Output is correct
13 Correct 979 ms 644 KB Output is correct
14 Correct 831 ms 640 KB Output is correct
15 Correct 674 ms 644 KB Output is correct
16 Correct 538 ms 760 KB Output is correct
17 Correct 662 ms 780 KB Output is correct
18 Correct 529 ms 1024 KB Output is correct
19 Correct 479 ms 1024 KB Output is correct
20 Correct 491 ms 768 KB Output is correct
21 Correct 76 ms 672 KB Output is correct
22 Correct 76 ms 856 KB Output is correct
23 Correct 108 ms 828 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 648 KB Output is correct
26 Correct 5 ms 648 KB Output is correct
27 Correct 4 ms 644 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 604 ms 800 KB Output is correct
30 Correct 605 ms 640 KB Output is correct
31 Correct 505 ms 640 KB Output is correct
32 Correct 548 ms 640 KB Output is correct
33 Correct 564 ms 892 KB Output is correct
34 Correct 355 ms 768 KB Output is correct
35 Correct 482 ms 1024 KB Output is correct
36 Correct 505 ms 1008 KB Output is correct
37 Correct 502 ms 800 KB Output is correct
38 Correct 495 ms 800 KB Output is correct
39 Correct 467 ms 768 KB Output is correct
40 Correct 441 ms 768 KB Output is correct
41 Correct 452 ms 932 KB Output is correct
42 Correct 61 ms 844 KB Output is correct
43 Correct 117 ms 812 KB Output is correct
44 Correct 141 ms 768 KB Output is correct
45 Correct 156 ms 768 KB Output is correct
46 Correct 309 ms 768 KB Output is correct
47 Correct 301 ms 792 KB Output is correct
48 Correct 74 ms 844 KB Output is correct
49 Correct 71 ms 928 KB Output is correct