Submission #309828

# Submission time Handle Problem Language Result Execution time Memory
309828 2020-10-04T15:38:56 Z emaborevkovic Stations (IOI20_stations) C++14
0 / 100
3000 ms 2097156 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.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:69:1: warning: control reaches end of non-void function [-Wreturn-type]
   69 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 1326 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3048 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1403 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 910 ms 612 KB Output is correct
2 Runtime error 1168 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2241 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -