Pagini recente » Cod sursa (job #1655389) | Cod sursa (job #2304075) | Cod sursa (job #1671061) | Cod sursa (job #1059720) | Cod sursa (job #2941962)
#include<bits/stdc++.h>
#define t int
using namespace std;ifstream i("apm.in");ofstream o("apm.out");const t h=3e5;t p[h];set<vector<t>>g[h+h],f;t a(t x){if(x^p[x])p[x]=a(p[x]);return p[x];}t n,m,x,y,c,s;main(){i>>n>>m;iota(p,p+h,0);while(m--)i>>x>>y>>c,g[c+h].insert({x,y});for(auto&z:g)for(auto&e:z){x=a(e[0]);y=a(e[1]);if(x^y)f.insert(e),s+=&z-g-h;p[x]=y;}o<<s<<' '<<n-1<<' ';for(auto&e:f)o<<e[0]<<' '<<e[1]<<' ';}