Submission #680851

#TimeUsernameProblemLanguageResultExecution timeMemory
680851aryan12Stations (IOI20_stations)C++17
100 / 100
871 ms856 KiB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int N = 1001;
int tin[N], tout[N], depth[N];
int tim = -1;
vector<int> g[N];

void dfs(int node, int par)
{
	tin[node] = (depth[node] % 2 == 1) ? ++tim : tim;
	for(int to: g[node])
	{
		if(to == par) continue;
		depth[to] = depth[node] + 1;
		dfs(to, node);
	}
	tout[node] = (depth[node] % 2 == 0) ? ++tim : tim;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	tim = -1;
	for(int i = 0; i < N; i++)
	{
		g[i].clear();
	}
	for(int i = 0; i < u.size(); i++)
	{
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	depth[0] = 1;
	dfs(0, -1);
	vector<int> labels;
	for(int i = 0; i < n; i++)
	{
		if(depth[i] % 2 == 1)
		{
			labels.push_back(tin[i]);
		}
		else
		{
			labels.push_back(tout[i]);
		}
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c[0] > s)
	{
		int starting = s + 1;
		for(int i = 0; i < c.size() - 1; i++)
		{
			if(starting <= t && t <= c[i])
			{
				return c[i];
			}
			starting = c[i] + 1;
		}
		return c[c.size() - 1];
	}
	else
	{
		int ending = s;
		for(int i = c.size() - 1; i > 0; i--)
		{
			if(c[i] <= t && t <= ending)
			{
				return c[i];
			}
			ending = c[i] - 1;
		}
		return c[0];
	}
}

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < u.size(); i++)
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i = 0; i < c.size() - 1; 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...