# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306428 | CaroLinda | Stations (IOI20_stations) | C++14 | 3231 ms | 2097156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include <bits/stdc++.h>
#define lp(i,a,b) for(int i = a; i < b; i++)
#define debug //printf
#define ff first
#define ss second
#define mk make_pair
#define ll long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())
const int MAXN = 1010 ;
using namespace std ;
int tin[MAXN] , tout[MAXN] , lvl[MAXN] ;
vector<int> adj[MAXN] ;
int currTime ;
void dfs(int x, int father)
{
tin[x] = tout[x] = ++currTime ;
for(auto e :adj[x])
{
if(e == father) continue ;
lvl[e] = !lvl[x] ;
dfs(e,x) ;
tout[x] = ++currTime ;
}
if( (tin[x]&1) != (tout[x]&1) ) tout[x]++ ;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i = 0 ; i <n-1 ; i++ )
{
adj[ u[i] ].push_back(v[i]) ;
adj[v[i]].push_back(u[i]) ;
}
dfs(0,-1) ;
vector<int> labels(n) ;
for(int i = 0 ; i < n ; i++ )
{
if(tin[i]&1) labels[i] = tin[i] ;
else labels[i] = tout[i] ;
}
lp(i,0,n) debug("%d %d\n" , i , labels[i]) ;
return labels ;
}
int find_next_station(int s, int t, std::vector<int> c) {
for(auto e: c ) if(e == t) return t ;
if( c[0]&1 )
{
//ou seja, tenho os tin's
if(t > s ) return c[0] ;
for(int i = sz(c) - 1 ; i>= 0 ; i-- )
if( c[i] < t ) return c[i] ;
return c[0] ;
}
else
{
//tenho os tout's
if( t < s ) return c[ sz(c)-1 ] ;
for(int i = 0 ; i < sz(c) ; i++ )
if( c[i] > t ) return c[i] ;
return c[ sz(c)-1 ] ;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |