답안 #321496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321496 2020-11-12T15:07:19 Z katearima 기지국 (IOI20_stations) C++14
0 / 100
52 ms 1004 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
vector<int> ans(N);
int i,n,k,m,x,j,t;
void DFS(vector<vector<int>> v, int x,int y,int d){
	if(d%2==0) ans[y]=t; t++;
	for(int i=0; i<v[y].size(); i++){
		if(v[y][i]==x) continue;
		DFS(v,y,v[y][i],d+1);
	}
	if(d%2!=0) ans[y]=t; t++;
	
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> label(n);
	vector<vector<int>> a(n);
	for(i=0; i<n-1; i++){
		a[u[i]].push_back(v[i]);
		a[v[i]].push_back(u[i]);
	}
    t=0;
	DFS(a,-1,0,0);
	for(i=0; i<n; i++){
		cout<<ans[i]<<endl;
	}
	for(i=0; i<n; i++) label[i]=ans[i];
	ans.clear();
	return label;
}

int find_next_station(int s, int t, vector<int> c) {
	bool parent=true;
	int ans;
	
	if(s<c[0]){
		c.insert(c.begin(),s);
		for(i=1; i<c.size()-1; i++){
			if(t<=c[i] && t>=c[i-1]+1) {ans=c[i]; parent=false;}
		}
		if(parent) ans=c[c.size()-1];
	}
	else{
		c.push_back(s);
		for(i=1; i<c.size()-1; i++){
			if(t>=c[i] && t<=c[i+1]-1) {ans=c[i]; parent=false;}
			if(parent) ans=c[0];
		}
		
	}
	//cout<<"ans"<<ans<<endl;
	return ans;
}

Compilation message

stations.cpp: In function 'void DFS(std::vector<std::vector<int> >, int, int, int)':
stations.cpp:9:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    9 |  if(d%2==0) ans[y]=t; t++;
      |  ^~
stations.cpp:9:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    9 |  if(d%2==0) ans[y]=t; t++;
      |                       ^
stations.cpp:10:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i=0; i<v[y].size(); i++){
      |               ~^~~~~~~~~~~~
stations.cpp:14:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   14 |  if(d%2!=0) ans[y]=t; t++;
      |  ^~
stations.cpp:14:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   14 |  if(d%2!=0) ans[y]=t; t++;
      |                       ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(i=1; i<c.size()-1; i++){
      |            ~^~~~~~~~~~~
stations.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(i=1; i<c.size()-1; i++){
      |            ~^~~~~~~~~~~
stations.cpp:54:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 1004 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -