Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- int n,m,A,B;
- struct ed{
- int a,b,l;
- };
- vector <ed> E;
- vector <int> pr,sz;
- bool sh = 1;
- int getp(int v){
- if (pr[v] == v){
- return v;
- }
- int p = getp(v);
- pr[v] = p;
- return p;
- }
- void un(int a, int b){
- a = getp(a);
- b = getp(b);
- if (a == b)return;
- //sz[b] > sz[a]
- if (sz[a] > sz[b]) swap(a,b);
- sz[b] += sz[a];
- pr[a] = b;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>m;
- map <pii, int> mtr;
- for (int i = 0; i < m; ++i){
- int a,b,l;
- cin>>a>>b>>l;
- if (a > b) swap(a,b);
- if (mtr.find({a,b}) == mtr.end()){
- mtr[{a,b}] = l;
- }
- else{
- mtr[{a,b}] = max(mtr[{a,b}], l);
- }
- }
- cin>>A>>B;
- for (auto p: mtr){
- //cout<<p.first.first<<' '<<p.first.second<<' '<<p.second<<"\n";
- E.push_back({p.first.first, p.first.second, p.second});
- }
- pr.resize(n);
- sz.assign(n,1);
- for (int i = 0; i < n; ++i){
- pr[i] = i;
- }
- for (ed e: E){
- un(e.a, e.b);
- }
- if (sh){
- cout<<"sz\n";
- cv(sz);
- cout<<"pr\n";
- cv(pr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement