Submission #675476

# Submission time Handle Problem Language Result Execution time Memory
675476 2022-12-27T10:28:28 Z QwertyPi Sightseeing (NOI14_sightseeing) C++14
15 / 25
2826 ms 134100 KB
#include <bits/stdc++.h>

using namespace std;

struct edge{
	int u, v, w;
	bool operator< (const edge& o) {
		return w < o.w;
	}
};

struct qry{
	int x, i;
	bool operator< (const qry& o) {
		return x < o.x;
	}
};

const int MAXN = 1e5 + 11;
int ans[MAXN];

int dsu[MAXN]; vector<int> sons[MAXN];
void init(int n){
	for(int i = 1; i <= n; i++) dsu[i] = i, sons[i].push_back(i);
}
int f(int x){
	return x == dsu[x] ? x : dsu[x] = f(dsu[x]);
}
void g(int x, int y, int w){
	x = f(x), y = f(y);
	if(x == y) return;
	if(f(1) == f(y)) swap(x, y);
	if(f(1) == f(x)){
		for(auto i : sons[y]){
			ans[i] = w;
		}
	}else{
		if(sons[x].size() < sons[y].size()) swap(x, y);
		for(auto i : sons[y]){
			sons[x].push_back(i);
		}
	}
	sons[y].clear();
	dsu[y] = x;
}

vector<edge> E[MAXN];
int main(){
	int n, m, q; cin >> n >> m >> q;
	for(int i = 0; i < m; i++){
		int u, v, w; cin >> u >> v >> w;
		E[w].push_back({u, v, w});
	}
	init(n);
	for(int j = MAXN - 1; j >= 0; j--){
		for(auto e : E[j]){
			g(e.u, e.v, e.w);
		}
	}
	
	for(int i = 0; i < q; i++){
		int x; cin >> x; cout << ans[x] << endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5144 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8716 KB Output is correct
2 Correct 54 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2826 ms 134100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -