//aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define scl(x) scanf("%lld", &x) #define scll(x,y) scanf("%lld %lld", &x, &y) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl #define prii(a,b) cout<<a<<" "<<b<<endl using namespace std; #define mx 200007 struct edge { int a,b,c; edge(int _a, int _b, int _c) { a=_a, b=_b, c=_c; } bool operator < (const edge p) const { return (c < p.c); } }; ll n,e; vector <edge> graph; ll par[mx]; ll presm = 0; int findr(int r) { if(r==par[r]) return r; int x = findr(par[r]); par[r] = x; return x; } ll mst() { ll mstsm = 0; // init REP(i,mx) par[i] = i; //find REP(i,SZ(graph)) { int x = findr(graph[i].a); int y = findr(graph[i].b); if(x!=y) par[y] = x , mstsm += graph[i].c; } return mstsm; } ll x,y,z; int main() { while(scll(n,e) and n+e) { presm = 0; REP(i,e) { scll(x,y); scl(z); graph.push_back(edge(x,y,z)); presm += z; } sort(ALL(graph)); ll res = presm - mst(); printf("%lld\n", res); graph.clear(); } return 0; }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
UVa 11631 - Dark Roads
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment