답안 #322165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322165 2020-11-14T07:25:23 Z socho 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
	srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
	long long a = rand();
	long long b = rand();
	return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
	freopen("problem.in", "r", stdin); 
	freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
// #define endl '\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

const int MXN = 500005;
int n, m, q;
vector<pair<int, pair<int, int>>> edges;

int score[MXN];
vector<pair<int, int>> adj[MXN];

int par[MXN];

int parent(int node) {
	if (par[node] == node) return node;
	return par[node] = parent(par[node]);
}

void connect(int a, int b) {
	a = parent(a); b = parent(b);
	par[a] = b;
}

void dfs(int node, int par, int curr) {
	score[node] = curr;
	for (auto x: adj[node]) {
		if (x.first == par) continue;
		dfs(x.first, node, min(curr, x.second));
	}
}

signed main() {

	ran(); fast();
	
	for (int i=0; i<MXN; i++) par[i] = i;

	cin >> n >> m >> q;
	for (int i=0; i<m; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		edges.push_back({w, {a, b}});
	}
	
	sort(edges.begin(), edges.end());
	reverse(edges.begin(), edges.end());
	
	for (auto x: edges) {
		int w = x.first, a = x.second.first, b = x.second.second;
		if (parent(a) == parent(b)) continue;
		adj[a].push_back({b, w});
		adj[b].push_back({a, w});
		connect(a, b);
	}
	
	dfs(1, -1, INT_MAX);
	
	for (int i=0; i<q; i++) {
		int x;
		cin >> x;
		cout << score[x] << endl;
	}
	
}

Compilation message

sightseeing.cpp: In function 'void usaco()':
sightseeing.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  freopen("problem.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  freopen("problem.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16108 KB Output is correct
2 Correct 14 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16236 KB Output is correct
2 Correct 10 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 19296 KB Output is correct
2 Correct 51 ms 19000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2609 ms 114688 KB Output is correct
2 Execution timed out 3595 ms 262144 KB Time limit exceeded