"CF" 135 Div2 choosing capital for Treeland

Source: Internet
Author: User

Tree-shaped structure, very interesting topic. Not hard.

1 /*219D*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at  - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A  the Const intMAXN = 2e5+5; + intD[MAXN]; - intW[MAXN], SW; $ intW_[MAXN]; $ Vpii E[MAXN]; - vi VC; - intans; the intN; - Wuyi voidDfsintUintFaintW_intd) { the     intV, W; -      WuD[u] =D; -W_[u] =W_; AboutRep (I,0, SZ (E[u])) { $v =E[u][i].fir; -W =e[u][i].sec; -         if(v = =FA) -             Continue; ADFS (V, u, w_+w, d+1); +W[u] + = W[v] +W; the     } - } $  the voidsolve () { the     //Calculate W & c theDfs1, -1,0,0); theAns = SW = w[1]; -VC.PB (1); in      the     //Calculate the minimum cost the     inttmp; About      theRep (I,2, n+1) { theTMP = Sw-w_[i] + d[i]-W_[i]; the         if(TMP = =ans) { + VC.PB (i); -}Else if(TMP <ans) { the vc.clear ();BayiAns =tmp; the VC.PB (i); the         } -     } -      theprintf"%d\n", ans); theRep (I,0, SZ (VC)) theprintf"%d", Vc[i]); thePutchar ('\ n'); - } the      the intMain () { theIos::sync_with_stdio (false);94 #ifndef Online_judge theFreopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout); the     #endif98      About     intu, v; -     101scanf"%d", &n);102Rep (I,1, N) {103scanf"%d%d", &u, &v);104E[U].PB (MP (V,0)); theE[V].PB (MP (U),1));106     }107     108 solve ();109      the #ifndef Online_judge111printf"Time =%d.\n", (int) clock ()); the     #endif113      the     return 0; the}

"CF" 135 Div2 choosing capital for Treeland

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.