mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:11:58 +00:00
parent
bd08e79678
commit
d901234bf4
67
S2OJ/1593/1593.cpp
Normal file
67
S2OJ/1593/1593.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 3e5 + 5;
|
||||
|
||||
int n, d[N];
|
||||
long long f[N][2];
|
||||
std::vector<std::pair<int, int>> g[N];
|
||||
|
||||
void dfs(int u, int fa) {
|
||||
std::vector<long long> weights;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
w = e.second;
|
||||
|
||||
if (v == fa) continue;
|
||||
|
||||
dfs(v, u);
|
||||
weights.push_back(f[v][0] + w - f[v][1]);
|
||||
|
||||
f[u][0] += f[v][1];
|
||||
f[u][1] += f[v][1];
|
||||
}
|
||||
|
||||
std::sort(weights.begin(), weights.end(), std::greater<>());
|
||||
|
||||
for (int i = 0; i < weights.size(); i++) {
|
||||
if (weights[i] <= 0) break;
|
||||
if (i < d[u] - 1) f[u][0] += weights[i];
|
||||
if (i < d[u]) f[u][1] += weights[i];
|
||||
}
|
||||
|
||||
if (!d[u]) f[u][0] = std::numeric_limits<int>::min();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> d[i];
|
||||
}
|
||||
|
||||
for (int i = 1, u, v, w; i < n; i++) {
|
||||
cin >> u >> v >> w;
|
||||
|
||||
g[u].emplace_back(v, w);
|
||||
g[v].emplace_back(u, w);
|
||||
}
|
||||
|
||||
dfs(1, 0);
|
||||
|
||||
cout << f[1][1] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1593/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data13.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data21.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data21.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data21.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data21.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data22.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data22.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data22.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data22.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data23.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data23.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data23.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data23.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data24.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data24.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data24.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data24.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data25.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data25.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data25.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data25.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data26.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data26.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data26.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data26.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data27.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data27.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data27.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data27.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data28.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data28.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data28.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data28.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data29.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data29.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data29.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data29.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data30.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data30.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data30.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data30.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data31.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data31.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data31.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data31.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data32.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data32.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data32.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data32.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data33.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data33.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data33.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data33.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data34.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data34.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data34.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data34.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data35.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data35.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data35.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data35.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data36.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data36.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data36.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data36.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data37.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data37.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data37.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data37.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data38.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data38.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data38.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data38.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data39.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data39.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data39.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data39.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data40.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data40.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data40.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data40.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data41.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data41.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data41.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data41.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data42.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data42.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data42.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data42.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data43.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data43.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data43.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data43.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data44.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data44.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data44.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data44.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data45.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data45.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data45.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data45.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data46.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data46.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data46.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data46.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data47.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data47.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data47.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data47.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data48.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data48.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data48.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data48.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data49.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data49.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data49.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data49.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data50.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data50.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data50.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data50.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data51.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data51.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data51.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data51.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1593/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1593/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user