답안 #1064885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064885 2024-08-18T18:55:43 Z thatsgonzalez 기지국 (IOI20_stations) C++14
0 / 100
277 ms 8704 KB
#include "stations.h"
#include <vector>

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


#define s second
#define f first

vector<vector<int>> dist;

int const inf = INT_MAX;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		labels[i] = i;
	}

	vector<vector<int>> tree(n);
	dist.assign(n,vector<int>(n,inf));

	for(int i = 0; i<n-1; i++){

		tree[u[i]].push_back(v[i]);
		tree[v[i]].push_back(u[i]);

	}

	for(int i = 0; i<n; i++){

		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
		dist[i][i] = 0;
		pq.push({0,i});

		while(!pq.empty()){
			int u = pq.top().s; int w = pq.top().f; pq.pop();

			if(dist[i][u]!=w) continue;

			for(auto &x: tree[u]){
				if(dist[i][x] > dist[i][u] + 1){
					dist[i][x] = dist[i][u] + 1;
					pq.push({dist[i][x],x});
				}
			}
		}

	}


	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int mn = INT_MAX;
	int res = -1;

	for(auto &x: c){
		if(dist[x][t]<mn){
			mn = dist[x][t]; res = x;
		}
	}

	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 112 ms 4780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 277 ms 8596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 113 ms 8704 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 8612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -