답안 #305244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305244 2020-09-22T19:21:58 Z oscarsierra12 기지국 (IOI20_stations) C++14
0 / 100
4 ms 760 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std ;

const int N = 1010 ;

int dfsNum[N];
int cnt = 0 ;
vector <int> G[N] ;

int dfs ( int u, int p, int f ) {
    if ( f ) dfsNum[u] = cnt++ ;
    for ( auto v:G[u] ) if ( v!=p ) dfs (v, u, 1-f) ;
    if ( !f ) dfsNum[u] = cnt++ ;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for ( int i = 0 ; i < n ; ++i ) G[i].clear() ;
	cnt = 0 ;
	for ( int i = 0 ; i + 1 < n ; ++i ) {
        G[u[i]].push_back ( v[i] ) ;
        G[v[i]].push_back ( u[i] ) ;
	}
    dfs ( 0, -1, 0 ) ;
	for (int i = 0; i < n; i++) {
		labels[i] = dfsNum[i];
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    sort ( c.begin(), c.end() ) ;
    if ( c[0] > s ) {
        ///s is timein
        if ( t < s ) return c.back() ;
        for ( auto i:c )
            if ( i >= t ) return i ;
        return -1 ;
    }
    ///s is timeout
    if ( s < t ) return c[0] ;
    for ( int i = 1 ; i < c.size() ; ++i )
        if ( c[i] > t ) return c[i-1] ;
	return c.back();
}

Compilation message

stations.cpp: In function 'int dfs(int, int, int)':
stations.cpp:17:1: warning: no return statement in function returning non-void [-Wreturn-type]
   17 | }
      | ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for ( int i = 1 ; i < c.size() ; ++i )
      |                       ~~^~~~~~~~~~
stations.cpp:45:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 |     for ( int i = 1 ; i < c.size() ; ++i )
      |     ^~~
stations.cpp:47:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   47 |  return c.back();
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -