Submission #730083

#TimeUsernameProblemLanguageResultExecution timeMemory
730083danikoynovStations (IOI20_stations)C++14
0 / 100
824 ms676 KiB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1010;
vector < int > g[maxn], order, my_labels;
int in[maxn], out[maxn], timer, par[maxn], depth[maxn];
void dfs(int v, int p)
{

    in[v] = timer ++;
    par[v] = p;
    order.push_back(v);
    for (int u : g[v])
    {

        if (u == p)
            continue;
        depth[u] = depth[v] + 1;
        dfs(u, v);
    }
    out[v] = timer ++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    for (int i = 0; i < n; i ++)
    {
        g[i].clear();
    }
    timer = 0;
    order.clear();
    my_labels.clear();
    for (int i = 0; i < v.size(); i ++)
    {
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    my_labels.resize(n);
    dfs(0, 0);
    for (int i = 0; i < n; i ++)
    {
        if (depth[i] % 2 == 0)
        my_labels[i] = in[i] + 2000;
        else
            my_labels[i] = out[i];
    }


    return my_labels;
}

int used[maxn];
int find_next_station(int s, int t, vector<int> c)
{
    ///return 0;
    vector < int > children;

    if (t > 2000)
        t -= 2000;
    if (s > 2000)
    {
        /// in time case

        sort(c.begin(), c.end());
        if (s - 2000 != 0)
        {
            if (c.size() == 1)
                return c[0];
            if (t < s - 2000)
                return c.back();
            if (t > c[c.size() - 2])
                return c.back();
            c.pop_back();
        }


        int pt = c.size() -1;
        while(pt >= 0 && t <= c[pt])
            pt --;
        pt ++;
        return c[pt];
    }
    else
    {
        sort(c.begin(), c.end());
        if (c.size() == 1)
            return c[0];
            ///cout << "here " << s << " " << t << endl;
        if (t > s)
            return c[0];

        if (t < c[1] - 2000)
            return c[0];
        c.erase(c.begin());

        int pt = 0;
        while(pt < c.size() && t >= c[pt] - 2000)
            pt ++;
        pt --;
        return c[pt];
    }
}

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:33:23: 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 < v.size(); i ++)
      |                     ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         while(pt < c.size() && t >= c[pt] - 2000)
      |               ~~~^~~~~~~~~~
#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...