답안 #430395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430395 2021-06-16T13:20:31 Z APROHACK 기지국 (IOI20_stations) C++14
0 / 100
3 ms 2640 KB
	#include "stations.h"
	#include <bits/stdc++.h>
	#include <vector>
	#define PB push_back
	using namespace std;
	vector<int>ady[100001];
	int lab[100001];
	long long cur = 0;
	void dfs(int node, int parent, bool fix){
		//cout<<node<<endl;
		if(fix)lab[node]=cur++;
		for(int i= 0 ; i < ady[node].size() ; i++){
			if(ady[node][i]==parent)continue;
			dfs(ady[node][i], node, !fix);
		}
		if(!fix)lab[node]=cur++;
	}
	vector<int> label(int n, int k, vector<int> u, vector<int> v) {
		cur=0;
		vector<int>ab;
		for(int i = 0 ; i <= n-1 ; i++){
			ady[i].clear();
		}
		for(int i = 0 ; i < n-1 ; i++){
			ady[u[i]].PB(v[i]);
			ady[v[i]].PB(u[i]);
		}
		dfs(0, -1, true);
		for(int i = 0 ; i <= n-1 ; i++){
			ab.PB(lab[i]);
			cout<<lab[i]<<" ";
		}
		return ab;
	}

	int find_next_station(int s, int t, vector<int>c) {
		
		//for(int i = 0 ; i <= ls ; i++){
		//	cout<<c[i]<<" ";
		//}
		//cout<<endl<<s<<" "<<t<<endl;
		int padre;
		if(c[0]>s){//califica de una
			padre = c[c.size()-1];
			if(t<s||t>c[c.size()-2])return padre;
			else{
				int li=0, ls=c.size()-2, pos;
				pos=(li+ls)/2;
				while(li+1<ls){
					//cout<<li<<" "<<ls<<endl;
					pos=(li+ls)/2;
					if(c[pos]>=t)ls=pos;
					else li=pos;
				}
				for(int i = ls ; i >= li ; i--){
					if(c[i]>=t)pos=i;
				}
				return c[pos];
			}
		}else{ // se espera
			padre = c[0];
			if(t>s||t<c[1])return padre;
			else{
				int li=0, ls=c.size()-2, pos;
				pos=(li+ls)/2;
				while(li+1<ls){
					//cout<<li<<" "<<ls<<endl;
					pos=(li+ls)/2;
					if(c[pos]<=t)li=pos;
					else ls=pos;
				}
				for(int i = li ; i <= ls ; i++){
					if(c[i]>=t)pos=i;
				}
				return c[pos];
			}
		}
		//pos=(li+ls)/2;
		//cout<<"a "<<c[pos]<<endl;
		//return c[pos];
	}

Compilation message

stations.cpp: In function 'void dfs(int, int, bool)':
stations.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i= 0 ; i < ady[node].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2632 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2640 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 2636 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2640 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 2632 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -