Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #define pb push_back
- #define sc second
- #define fs first
- using namespace std;
- typedef long long lli;
- struct trine{
- int a;
- int b;
- int c;
- trine(int a1, int b2, int c3){
- a = a1;
- b = b2;
- c = c3;
- }
- trine () {
- a = 0;
- b = 0;
- c = 0;
- }
- bool operator< (trine other){
- if (other.a < a){return false;
- }
- if ((other.a == a)&&(other.b < b)){
- return false;
- }
- if (((other.a == a)&&(other.b == b))&&( other.c < c)){
- return false;
- }
- return true;
- }
- };
- const int maxn = 1e5+5;
- int sp[maxn], p[maxn], sz[maxn];
- int ans = 0, k;
- int get (int v){
- if (p[v] == v){return v;}
- return p[v] = get(p[v]);
- }
- void unite (int v , int u , int wei){
- v = get(v);
- u = get(u);
- if (v != u){
- if (sz[u] < sz[v]){swap(v,u);}
- p[v] = u;
- sz[u] += sz[v];
- sp[u] += sp[v];
- if (sp[u] == k){
- ans = wei;
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, m, x, y, z;
- cin >> n >> m >> k;
- for (int i = 0; i <= n; ++i){
- p[i] = i;
- sz[i] = 1;
- }
- for (int i = 0 ; i < k; ++i){
- cin >> x;
- sp[x] = 1;
- }
- vector <trine> e(m);
- for (int i = 0; i < m; ++i){
- cin >> x >> y >> z;
- e[i] = trine(z, x, y);
- }
- sort(e.begin(), e.end());
- for (auto k : e){
- unite(k.b, k.c, k.a);
- if (ans != 0){
- break;
- }
- }
- for (int i = 0; i < k; ++i){
- cout << ans << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement