# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1137194 | thunopro | Stations (IOI20_stations) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std ;
#define maxn 200009
#define ll long long
#define pb push_back
#define fi first
#define se second
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
#define TIME ( 1.0*clock() / CLOCKS_PER_SEC )
const int mod = 1e9+7 ;
const int INF = 1e9 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
}
mt19937 rng (time(0)) ;
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
vi label ( int n , int k , vi u , vi v ) ;
int find_next_station ( int source , int target , vi list ) ;
int n , k ;
vi adjList [maxn] ;
vi Label ;
int timeDfs ;
int tin [maxn] , tout [maxn] ;
void dfs ( int u , int par = -1 )
{
tin [u] = timeDfs ++ ;
for ( auto v : adjList [u] )
{
if ( v == par ) continue ;
dfs (v,u) ;
}
tout [u] = timeDfs ;
}
void reset ()
{
timeDfs = 0 ; Label . assign (n,0) ;
for ( int i = 0 ; i < n ; i ++ ) adjList [i] . clear () ;
}
vi label ( int N , int K , vi U , vi V )
{
n = N , k = K ;
reset () ;
for ( int i = 0 ; i < U.size () ; i ++ )
{
int u = U [i] , v = V [i] ;
adjList [u] . pb (v) ;
adjList [v] . pb (u) ;
}
dfs (0) ;
for ( int i = 0 ; i < n ; i ++ ) Label [i] = (tin[i]*1000+tout[i]) ;
return Label ;
}
int find_next_station ( int source , int target , vi list )
{
sort (list.begin(),list.end()) ;
int tin_source = source / 1000 ;
int tout_source = source % 1000 ;
int tin_target = target / 1000 ;
int tout_target = target % 1000 ;
if ( tin_target < tin_source || tin_target > tout_source )
{
return list [0] ;
}
else
{
for ( auto x : list )
{
int tin_x = x / 1000 ;
int tout_x = x % 1000 ;
if ( tin_x >= tin_source && tin_x <= tin_source ) return x ;
}
}
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// rf () ;
vi answer_Label = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4}) ;
for ( auto x : answer_Label ) cout << x << " " ; cout << endl ;
int source , target ; cin >> source >> target ;
int source_x , target_x ;
for ( int i = 0 ; i < answer_Label.size () ; i ++ )
{
if ( answer_Label [i] == source ) source_x = i ;
if ( answer_Label [i] == target ) target_x = i ;
}
cout << "source target: " << source_x << " " << target_x << "\n" ;
vi neigh ;
for ( auto x : adjList[source_x] ) neigh . pb (answer_Label[x]) ;
cout << find_next_station (source,target,neigh) ;
}