Submission #347210

# Submission time Handle Problem Language Result Execution time Memory
347210 2021-01-12T11:19:51 Z blue Stations (IOI20_stations) C++17
0 / 100
856 ms 980 KB
#include "stations.h"
#include <vector>
using namespace std;

vector<int> edge[1000];
vector<int> subtree(1000, 0);
vector<int> res;

void dfs1(int u)
{
    subtree[u] = 1;
    for(int v: edge[u])
    {
        if(subtree[v]) continue;
        dfs1(v);
        subtree[u] += subtree[v];
    }
}

//               left/right, lower limit, upper limit
void dfs2(int u, bool flag, int a, int b)
{
    if(flag == 0)
    {
        res[u] = a;
        a++;
    }
    else
    {
        res[u] = b;
        b--;
    }

    for(int v: edge[u])
    {
        if(res[v] != -1) continue;
        dfs2(v, !flag, a, a + subtree[v] - 1);
        a += subtree[v];
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    for(int i = 0; i < n-1; i++)
    {
        edge[u[i]].push_back(v[i]);
        edge[v[i]].push_back(u[i]);
    }

    dfs1(0);

    res = vector<int>(n, -1);
    dfs2(0, 0, 0, n-1);

    return res;
}







int find_next_station(int s, int t, vector<int> c)
{
    if(s < c[0]) // s is a left label
    {
        if(t < s) return c.back();
        for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
    }
    else //s is a right label
    {
        if(t > s) return c.front();
        for(int i = c.size() - 1; i >= 0; i--) if(t >= c[i]) return c[i];
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
      |                        ~~^~~~~~~~~~
stations.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 492 KB Invalid labels (duplicates values). scenario=2, label=99
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 492 KB Invalid labels (duplicates values). scenario=3, label=968
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 492 KB Invalid labels (duplicates values). scenario=1, label=118
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 856 ms 896 KB Output is correct
2 Incorrect 675 ms 980 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 492 KB Invalid labels (duplicates values). scenario=1, label=191
2 Halted 0 ms 0 KB -