【codeforces 19/10/24 div2】E. Voting

时间:2019-10-25
本文章向大家介绍【codeforces 19/10/24 div2】E. Voting,主要包括【codeforces 19/10/24 div2】E. Voting使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
 1 #include<iostream>
 2 #include<string>
 3 #include<queue>
 4 #include<stack>
 5 #include<vector>
 6 #include<map>
 7 #include<cstdio>
 8 #include<cstdlib>
 9 #include<algorithm>
10 #include<set>
11 #include<list>
12 #include<iomanip>
13 #include<cstring>
14 #include<cmath>
15 #include<limits>
16 using namespace std;
17 
18 #define au auto
19 #define debug(i) cout<<"<debug> "<<i<<" <\debug>"<<endl
20 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
21 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
22 #define LLL __int128
23 #define Re register
24 #define il inline
25 #define mem(a,b) memset(a,(b),sizeof(a))
26 typedef pair<int, int> intpair;
27 typedef pair<long long int, long long int> llpair;
28 typedef long long int LL;
29 const int INF = 0x3f3f3f3f;
30 const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
31 
32 const int maxn = 300010;
33 
34 int T;
35 int n;
36 vector<int>g[maxn];
37 
38 int main()
39 {
40     ios::sync_with_stdio(0);
41     cin.tie(0);
42     cout.tie(0);
43     cin >> T;
44     while (T--)
45     {
46         priority_queue<int, vector<int>, greater<int>>heap;
47         cin >> n;
48         mfor(i, 0, n)
49         {
50             g[i].clear();
51         }
52         mfor(i, 1, n)
53         {
54             int a, b;
55             cin >> a >> b;
56             g[a].push_back(b);
57         }
58         LL ans = 0;
59         mrep(i, n - 1, 0)
60         {
61             mfor(j, 0, (int)g[i].size() - 1)
62             {
63                 heap.push(g[i][j]);
64             }
65             while (heap.size() > n - i)
66             {
67                 ans += heap.top();
68                 heap.pop();
69             }
70         }
71         cout << ans << endl;
72     }
73     return 0;
74 }
View Code

原文地址:https://www.cnblogs.com/thjkhdf12/p/11738703.html