답안 #306428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306428 2020-09-25T14:40:35 Z CaroLinda 기지국 (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#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

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:59:18: warning: left operand of comma operator has no effect [-Wunused-value]
   59 |  lp(i,0,n) debug("%d %d\n" , i , labels[i]) ;
      |                  ^~~~~~~~~
stations.cpp:59:42: warning: right operand of comma operator has no effect [-Wunused-value]
   59 |  lp(i,0,n) debug("%d %d\n" , i , labels[i]) ;
      |                                          ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1677 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3039 ms 752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1774 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 933 ms 1032 KB Output is correct
2 Runtime error 1411 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3231 ms 2042872 KB Time limit exceeded
2 Halted 0 ms 0 KB -