답안 #321951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321951 2020-11-13T14:17:23 Z katearima 기지국 (IOI20_stations) C++14
0 / 100
54 ms 1536 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
vector<vector<int>> a(N);
vector<int> ans(N);
int i,n,k,m,x,j,t;
void DFS(vector<vector<int>> a, int x,int y,int d){
	if(d%2==0) ans[y]=t; t++;
	for(int i=0; i<a[y].size(); i++){
		if(a[y][i]==x) continue;
		DFS(a,y,a[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);
	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(); a.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(int 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(int 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:10:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   10 |  if(d%2==0) ans[y]=t; t++;
      |  ^~
stations.cpp:10:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   10 |  if(d%2==0) ans[y]=t; t++;
      |                       ^
stations.cpp:11:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i=0; i<a[y].size(); i++){
      |               ~^~~~~~~~~~~~
stations.cpp:15:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |  if(d%2!=0) ans[y]=t; t++;
      |  ^~
stations.cpp:15:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |  if(d%2!=0) ans[y]=t; t++;
      |                       ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i=1; i<c.size()-1; i++){
      |                ~^~~~~~~~~~~
stations.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int 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 2 ms 1132 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 1536 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -