답안 #307364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307364 2020-09-28T02:17:16 Z arthur_nascimento 기지국 (IOI20_stations) C++14
0 / 100
1 ms 504 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

#define maxn 1010
int ini[maxn];
int fim[maxn];
int h[maxn];
vector<int> L[maxn];

int cur = 0;
void dfs(int x){
	printf("dfs %d\n",x);
	ini[x] = cur++;
	for(int i : L[x])
		if(ini[i] == 0 && i > 0){
			h[i] = 1 + h[x];
			dfs(i);
		}
	fim[x] = cur++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	for(int i=0;i<n;i++)
		L[i].clear();
	for(int i=0;i<n-1;i++){
		L[u[i]].pb(v[i]);
		L[v[i]].pb(u[i]);
	}
	dfs(0);
	vector<int> ret;
	for(int i=0;i<n;i++){
		if(h[i]%2 == 0)
			ret.pb(ini[i]);
		else
			ret.pb(fim[i]);
	}
	for(int i : ret)
		printf("%d ",i);
	printf("\n");
	return ret;
}

int find_next_station(int s, int t, std::vector<int> c) {
	printf("qr %d %d ~",s,t); for(int i : c) printf("%d ",i); printf("\n");
	if(c.size() == 1) return c[0];
	sort(c.begin(), c.end());
	if(s < c[0]){
		// S é entrada, c[i] é saida
		int pai = c[c.size()-1];
		if(t < s) return pai;
		if(c.size() >= 2 && t > c[c.size()-2]) return pai;
		for(int i=0;i<c.size();i++){
			if(t <= c[i])
				return c[i];
		}
		
	}
	else {
		// S é saida, c[i] é entrada
		int pai = c[0];
		if(t > s) return pai;
		if(t < c[1]) return pai;
		for(int i=1;i<c.size()-1;i++){
			if(t < c[i+1]) return c[i];
		}
		return c[c.size()-1];
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=1;i<c.size()-1;i++){
      |               ~^~~~~~~~~~~
stations.cpp:70:1: warning: control reaches end of non-void function [-Wreturn-type]
   70 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Expected integer, but "dfs" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "dfs" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "dfs" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "dfs" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 504 KB Expected integer, but "dfs" found
2 Halted 0 ms 0 KB -