Submission #711972

#TimeUsernameProblemLanguageResultExecution timeMemory
711972boris_mihovStations (IOI20_stations)C++17
0 / 100
3058 ms2097152 KiB
#include "stations.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 1000 + 10;

int n;
int timer;
int in[MAXN];
int out[MAXN];
bool which[MAXN];
std::vector <int> g[MAXN];

void dfs(int node, int p)
{
    in[node] = timer++;
    for (const int &i : g[node])
    {
        if (i == p) continue;
        which[i] = 1 ^ which[node];
        dfs(i, node);
    }

    out[node] = timer++;
}

std::vector <int> label(int _n, int k, std::vector <int> u, std::vector <int> v) 
{
    n = _n;
    std::fill(which, which + n, 0);
    for (int i = 0 ; i < n - 1 ; ++i)
    {
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }

    timer = 0;
    dfs(0, -1);
	std::vector <int> labels(n);
	for (int i = 0 ; i < n ; ++i) 
    {
		labels[i] = (which[i] ? in[i] : out[i]);
	}

	return labels;
}

int find_next_station(int s, int t, std::vector <int> c) 
{
	std::sort(c.begin(), c.end());
    if (s < c[0]) // in time
    {
        if (t < s)
        {
            return c.back();
        }

        for (int i = 0 ; i < (int)(c.size() - 1) ; ++i)
        {
            if (c[i] >= t)
            {
                return c[i];
            }
        }

        return c.back();
    } else
    {
        if (t > s)
        {
            return c[0];
        }

        for (int i = c.size() - 1 ; i > 0 ; --i)
        {
            if (c[i] <= t)
            {
                return c[i];
            }
        }

        return c[0];
    }

    std::cout << "WTF\n";
}
#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...