Submission #433362

# Submission time Handle Problem Language Result Execution time Memory
433362 2021-06-19T16:06:43 Z Enkognit Stations (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

vector<ll> c[100005];
vector<int> vv;
ll T;

void dfs(int h,int k=0, int p=-1)
{
    if (k%2==0) vv[h]=(++T);
    for (int i = 0; i < c[h].size(); i++)
        if (c[h][i]!=p)
        {
            dfs(c[h][i], k+1, h);
        }
    if (k%2) vv[h]=++T;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {

	vv.resize(n,0);

	for (int i = 0; i < n-1; i++)
    {
        c[u[i]].pb(v[i]);
        c[v[i]].pb(u[i]);
    }


    dfs(0);
    //cout << "---\n";

	return vv;
}

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

    }else
    {
        if (!(t<s && t>c[0])) return c[0];
        ll lst=s;
        for (int i = c.size()-1; i > -1; i--)
            if (t<lst && t>=c[i]) return c[i]; else lst=c[i];
    }
    //assert(0);
    return 0;
}
/*
1
5 10
0 1
1 2
1 3
2 4
2
2 0 2
1 3 3
*/

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < c[h].size(); i++)
      |                     ~~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int i = 1; i < c.size(); i++)
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2568 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3059 ms 2796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1287 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 837 ms 5264 KB Output is correct
2 Runtime error 1042 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2265 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -