Submission #396075

# Submission time Handle Problem Language Result Execution time Memory
396075 2021-04-29T12:25:56 Z InternetPerson10 Stations (IOI20_stations) C++17
Compilation error
0 ms 0 KB
#include "stations.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<vector<int>> adj;
vector<int> sub;
vector<int> labels;

int sub_calc(int v, int par) {
	int ans = 1;
	for(int i = 0; i < (int)adj[v].size(); i++) {
		if(adj[v][i] == par) continue;
		ans += sub_calc(adj[v][i], v);
	}
	// cout << v << ' ' << ans << '\n';
	sub[v] = ans;
	return sub[v];
}

void rec(int v, int l, int u, int par, int d) { // even: min, odd: max
	if(d%2) { 
		labels[v] = u-1;
		u--;
	}
	else {
		labels[v] = l;
		l++;
	}
	for(int i = 0; i < (int)adj[v].size(); i++) {
		if(adj[v][i] == par) continue;
		rec(adj[v][i], l, l + sub[adj[v][i]], v, d+1);
		l += sub[adj[v][i]];
	}
	// cout << v << ' ' << labels[v] << '\n';
	return;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for(int i = 0; i < n; i++) {
		abs.push_back(0);
		sub.push_back(0);
		labels.push_back(0):
	}
	for(int i = 0; i < n-1; i++) {
		int x = u[i];
		int y = v[i];
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	sub_calc(0, -1);
	rec(0, 0, n, -1, 0);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	return c[0];
	if(s < c[0]) {
		sort(c.begin(), c.end());
		if(t < s) return c[c.size() - 1];
		for(int i = 0; i < (int)c.size(); i++) {
			if(t <= c[i]) return c[i];
		}
		return c[c.size()-1];
	}
	else {
		sort(c.rbegin(), c.rend());
		if(t >= s) return c[c.size() - 1];
		for(int i = 0; i < (int)c.size(); i++) {
			if(t >= c[i]) return c[i];
		}
		return c[c.size()-1];
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:43:7: error: overloaded function with no contextual type information
   43 |   abs.push_back(0);
      |       ^~~~~~~~~
stations.cpp:45:22: error: expected ';' before ':' token
   45 |   labels.push_back(0):
      |                      ^
      |                      ;