답안 #304961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304961 2020-09-22T09:35:34 Z Wu_Ren 기지국 (IOI20_stations) C++14
0 / 100
1 ms 384 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>ans;
int head[1010],o,cnt;
struct edge{
	int to,link;
}e[2010];
void add_edge(int u,int v){
	e[++o].to=v,e[o].link=head[u],head[u]=o;
	e[++o].to=u,e[o].link=head[v],head[v]=o;
}
void dfs(int u,int pre,int dep){
	if(dep&1) ans[u]=cnt++;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].to==pre) continue;
		dfs(e[i].to,u,dep+1);
	}
	if(!(dep&1)) ans[u]=cnt++;
}
vector<int> label(int n,int k,vector<int>u,vector<int>v){
	for(int i=0;i<n;i++) head[i]=0;cnt=o=0;
	ans.resize(n),ans.clear();
	for(int i=0;i<n-1;i++) add_edge(u[i],v[i]);
	dfs(0,-1,1);
	return ans;
}

int find_next_station(int s,int t,vector<int>c) {
	if(s<c[0]){
		if(t<s) return c[c.size()-1];
		if(t>=c[c.size()-1]) return c[c.size()-1];
		for(int i=0;i<(int)c.size();i++) if(t<=c[i]) return c[i];
	}
	else{
		if(t>s) return c[0];
		if(t<c[1]) return c[0];
		for(int i=c.size()-1;i>=0;i--) if(t>=c[i]) return c[i];
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:22:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   22 |  for(int i=0;i<n;i++) head[i]=0;cnt=o=0;
      |  ^~~
stations.cpp:22:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   22 |  for(int i=0;i<n;i++) head[i]=0;cnt=o=0;
      |                                 ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 376 KB Invalid length of array as the response of 'label'. scenario=0, n=10, len=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=996, len=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 288 KB Invalid length of array as the response of 'label'. scenario=0, n=2, len=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Invalid length of array as the response of 'label'. scenario=0, n=2, len=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=3, len=0
2 Halted 0 ms 0 KB -