답안 #985414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985414 2024-05-17T19:14:49 Z sopaconk 기지국 (IOI20_stations) C++17
100 / 100
593 ms 1484 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
void dfs(int n, int par, vector<int> &ini, vector<int>&fin, vector<int> &prof,  vector<vector<int>> &adj, int &cont, int &height){
	ini[n]=cont;
	prof[n]=height;
	height++;
	for(int x: adj[n]){
		if(x==par) continue;
		cont++;
		dfs(x, n, ini, fin, prof, adj, cont, height);
	}
	height--;
	cont++;
	fin[n]=cont;
}


vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> ans (n);
	vector<int> ini (n);
	vector<int> fin (n);
	vector<int> prof (n);
	int cont=0;
	vector<vector<int>> adj (n);
	for(int i=0; i<n-1; ++i){
		adj[u[i]].pb(v[i]);
		adj[v[i]].pb(u[i]);
	}
	int height=0;
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
	dfs(0, -1, ini, fin, prof, adj, cont, height);
	for(int i=0; i<n; ++i){
		if(prof[i]%2){
			ans[i]=ini[i];
		}
		else{
			ans[i]=fin[i];
		}
		pq.push({ans[i], i});
	}
	int aux=0;
	while(!pq.empty()){
		int x=pq.top().first;
		int y=pq.top().second;
		pq.pop();
		ans[y]=aux;
		aux++;
	}
	return ans;
}

int find_next_station(int s, int t, vector<int> c) {
	if(c.size()==1) return c[0];
	int x=c.size();
	if(c[0]>s){
		if(t<s) return c[x-1];
		if(t>c[x-2]) return c[x-1];
		for(int i=0; i<x-1; ++i){
			if(t<=c[i]) return c[i];
		}
	}
	else{
		if(t>s) return c[0];
		if(t<c[1]) return c[0];
		for(int i=1; i<x; ++i){
//			if(t==c[i]) return c[i];
			if(t<c[i]) return c[i-1];
		}
		return c[x-1];
	}
	return c[0];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:46:7: warning: unused variable 'x' [-Wunused-variable]
   46 |   int x=pq.top().first;
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 976 KB Output is correct
2 Correct 275 ms 976 KB Output is correct
3 Correct 531 ms 684 KB Output is correct
4 Correct 422 ms 684 KB Output is correct
5 Correct 376 ms 688 KB Output is correct
6 Correct 288 ms 956 KB Output is correct
7 Correct 270 ms 940 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 1060 KB Output is correct
2 Correct 329 ms 800 KB Output is correct
3 Correct 540 ms 936 KB Output is correct
4 Correct 494 ms 684 KB Output is correct
5 Correct 404 ms 684 KB Output is correct
6 Correct 282 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 976 KB Output is correct
2 Correct 286 ms 976 KB Output is correct
3 Correct 573 ms 684 KB Output is correct
4 Correct 425 ms 684 KB Output is correct
5 Correct 364 ms 684 KB Output is correct
6 Correct 288 ms 984 KB Output is correct
7 Correct 274 ms 940 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 427 ms 684 KB Output is correct
12 Correct 296 ms 976 KB Output is correct
13 Correct 328 ms 1052 KB Output is correct
14 Correct 283 ms 684 KB Output is correct
15 Correct 31 ms 768 KB Output is correct
16 Correct 42 ms 856 KB Output is correct
17 Correct 59 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 684 KB Output is correct
2 Correct 499 ms 684 KB Output is correct
3 Correct 381 ms 684 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 392 ms 684 KB Output is correct
8 Correct 584 ms 688 KB Output is correct
9 Correct 394 ms 684 KB Output is correct
10 Correct 387 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 0 ms 1012 KB Output is correct
16 Correct 356 ms 684 KB Output is correct
17 Correct 335 ms 684 KB Output is correct
18 Correct 342 ms 684 KB Output is correct
19 Correct 338 ms 940 KB Output is correct
20 Correct 340 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 327 ms 972 KB Output is correct
2 Correct 295 ms 968 KB Output is correct
3 Correct 572 ms 684 KB Output is correct
4 Correct 456 ms 684 KB Output is correct
5 Correct 391 ms 1032 KB Output is correct
6 Correct 273 ms 980 KB Output is correct
7 Correct 309 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 276 ms 1144 KB Output is correct
12 Correct 321 ms 840 KB Output is correct
13 Correct 576 ms 936 KB Output is correct
14 Correct 412 ms 684 KB Output is correct
15 Correct 378 ms 684 KB Output is correct
16 Correct 322 ms 684 KB Output is correct
17 Correct 373 ms 684 KB Output is correct
18 Correct 276 ms 1200 KB Output is correct
19 Correct 311 ms 1484 KB Output is correct
20 Correct 295 ms 684 KB Output is correct
21 Correct 41 ms 768 KB Output is correct
22 Correct 38 ms 876 KB Output is correct
23 Correct 60 ms 1196 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 3 ms 944 KB Output is correct
28 Correct 1 ms 760 KB Output is correct
29 Correct 312 ms 684 KB Output is correct
30 Correct 320 ms 680 KB Output is correct
31 Correct 303 ms 684 KB Output is correct
32 Correct 303 ms 684 KB Output is correct
33 Correct 357 ms 684 KB Output is correct
34 Correct 226 ms 928 KB Output is correct
35 Correct 287 ms 1404 KB Output is correct
36 Correct 274 ms 1044 KB Output is correct
37 Correct 297 ms 1224 KB Output is correct
38 Correct 312 ms 992 KB Output is correct
39 Correct 290 ms 1172 KB Output is correct
40 Correct 285 ms 1004 KB Output is correct
41 Correct 302 ms 988 KB Output is correct
42 Correct 37 ms 924 KB Output is correct
43 Correct 64 ms 964 KB Output is correct
44 Correct 91 ms 876 KB Output is correct
45 Correct 105 ms 880 KB Output is correct
46 Correct 194 ms 884 KB Output is correct
47 Correct 205 ms 924 KB Output is correct
48 Correct 33 ms 1196 KB Output is correct
49 Correct 32 ms 1240 KB Output is correct