Submission #720225

#TimeUsernameProblemLanguageResultExecution timeMemory
720225thimote75Stations (IOI20_stations)C++14
100 / 100
935 ms752 KiB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

#define idata vector<int>
#define graph vector<idata>

graph roads;

int component = 0;
void dfs (int node, int parent, bool type, idata &labels) {
	if (type) {
		labels[node] = component;
		component ++;
	}

	for (int next : roads[node]) if (next != parent)
		dfs(next, node, !type, labels);
	
	if (!type) {
		labels[node] = component;
		component ++;
	}
}

idata label(int n, int k, idata u, idata v) {
	component = 0;
	roads.clear();
	roads.resize(n);
	
	for (int i = 0; i + 1 < n; i ++) {
		roads[u[i]].push_back(v[i]);
		roads[v[i]].push_back(u[i]);
	}

	idata labels(n);
	dfs(0, -1, true, labels);

	return labels;
}

int find_next_station(int s, int t, idata c) {
	bool is_root = s == 0;
	bool is_revr = c[0] < s;

	if (is_revr) {
		for (int i = 0; i < c.size(); i ++)
			c[i] = - c[i];
		s = -s;
		t = -t;
	}
	sort(c.begin(), c.end());

	int size = c.size();
	if (!is_root) size --;

	int result = c[c.size() - 1];
	for (int h = 0; h < size; h ++) {
		if (s < t && t <= c[h]) {
			result = c[h];
			break ;
		}
	}

	return is_revr ? -result : result;
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int i = 0; i < c.size(); i ++)
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...