답안 #431602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431602 2021-06-17T13:29:44 Z dreezy 기지국 (IOI20_stations) C++17
0 / 100
903 ms 620 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pi pair<int,int>

vector<int> labels;
vector<vector<int>> graph;

vector<pi> ord;
int cnt = 0;
void dfs1(int n,int p){//calc sizes
	ord[n].first = cnt++;
	for(int adj : graph[n])
	{
		if(adj == p) continue;
		dfs1(adj, n);
	}
	ord[n].second = cnt++;
}



void name_subtree(int n, int p, bool first){
	if(first)
		labels[n] = ord[n].first;
	else
		labels[n] = ord[n].second;
	for(int adj : graph[n]){
		if(adj == p)
		continue;
		name_subtree(adj, n, !first);
	}
}


vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	cnt = 0;
	ord.clear();
	labels.clear();
	graph.clear();
	ord.assign(n, {0,0});
	labels.assign(n, 0);
	graph.assign( n, vector<int>());
	for (int i = 0; i < n - 1; i++) {
		graph[u[i]].pb(v[i]);
		graph[v[i]].pb(u[i]);
	}
	

	dfs1(0,-1);
	int root = 0;
	//for(int i =0; i<n; i++) cout <<i<<": "<< ord[i].first<<", "<<ord[i].second<<endl;
	
	name_subtree(root, -1, 1);
	//for(int i =0; i<n; i++) cout <<i<<": "<< labels[i]<<endl;
	
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if(c.size() == 1) return c[0];
	
	bool isfirst = c[0] > s;

	
	if(isfirst){
		if(t < s) return c[c.size() - 1];
		for(int adj : c){
			if(t <= adj) return adj;
		}
		return c[c.size()-1] ;
	}
	else{
		if( t > s) return c[0];
		reverse(c.begin(), c.end());
		for(int adj : c)
			if(t >= adj)
				return adj;
		return c[0];
	}
	
	return c[0];
}


/************/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 416 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 412 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 537 ms 620 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 903 ms 528 KB Output is correct
2 Correct 623 ms 488 KB Output is correct
3 Correct 602 ms 488 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Incorrect 6 ms 468 KB Wrong query response.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 535 ms 608 KB Wrong query response.
2 Halted 0 ms 0 KB -