답안 #1073792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073792 2024-08-24T21:17:00 Z thatsgonzalez 기지국 (IOI20_stations) C++14
0 / 100
627 ms 856 KB
#include "stations.h"
#include <vector>

#include <bits/stdc++.h>
using namespace std;


#define pb push_back

int mn = 1;
map<int,bool> mp;

int dfs(int node, int p, vector<vector<int>> &g, vector<int> &sub_tree){

	for(auto &x: g[node]){
		if(x == p) continue;

		sub_tree[node]+=dfs(x,node,g,sub_tree);

	}

	return sub_tree[node]=sub_tree[node]+1;

}

void calc_labels(int node, int p, int t, vector<vector<int>> &g, vector<int> &sub_tree, vector<int> &labels){
	if(t){
		mp[mn+sub_tree[node]-1] = 1;
		labels[node] = mn+sub_tree[node]-1;
	}
	else{
		while(mp[mn]) mn++;
		mp[mn] = 1;
		labels[node] = mn; while(mp[mn]) mn++;
	}
	for(auto &x: g[node]){
		if(x == p) continue;
		int turno = t^1;
		calc_labels(x,node,turno,g,sub_tree,labels);
	}

}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	
	vector<int> sub_tree(n,0);
	vector<vector<int>> g(n);
	vector<int> labels(n);

	for(int i = 0; i<n-1; i++){
		g[u[i]].pb(v[i]);
		g[v[i]].pb(u[i]);
	}


	dfs(0,-1,g,sub_tree);
	calc_labels(0,-1,1,g,sub_tree,labels);


	return labels;
}

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

}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int i = 0; i<c.size()-1; i++){
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 856 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1009
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 856 KB Invalid labels (duplicates values). scenario=0, label=973
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 600 KB Invalid labels (duplicates values). scenario=3, label=2004
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 684 KB Output is correct
2 Incorrect 454 ms 684 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 852 KB Invalid labels (duplicates values). scenario=1, label=999
2 Halted 0 ms 0 KB -