mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
F - Select Edges
https://atcoder.jp/contests/abc259/submissions/35168987
This commit is contained in:
parent
d901234bf4
commit
c9d9bc6254
67
AtCoder/ABC259/F/F.cpp
Normal file
67
AtCoder/ABC259/F/F.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
AtCoder/ABC259/F/data/000.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/000.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/000.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/000.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/001.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/001.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/001.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/001.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/002.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/002.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/002.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/002.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/003.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/003.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/003.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/003.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/004.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/004.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/004.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/004.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/005.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/005.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/005.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/005.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/006.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/006.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/006.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/006.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/007.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/007.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/007.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/007.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/008.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/008.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/008.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/008.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/009.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/009.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/009.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/009.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/010.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/010.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/010.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/010.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/011.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/011.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/011.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/011.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/012.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/012.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/012.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/012.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/013.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/013.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/013.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/013.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/014.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/014.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/014.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/014.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/015.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/015.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/015.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/015.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/016.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/016.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/016.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/016.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/017.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/017.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/017.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/017.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/018.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/018.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/018.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/018.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/019.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/019.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/019.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/019.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/020.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/020.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/020.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/020.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/021.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/021.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/021.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/021.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/022.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/022.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/022.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/022.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/023.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/023.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/023.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/023.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/024.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/024.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/024.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/024.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/025.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/025.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/025.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/025.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/026.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/026.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/026.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/026.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/027.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/027.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/027.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/027.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/028.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/028.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/028.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/028.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/029.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/029.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/029.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/029.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/030.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/030.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/030.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/030.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/031.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/031.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/031.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/031.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/032.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/032.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/032.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/032.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/033.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/033.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/033.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/033.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/034.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/034.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/034.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/034.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/035.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/035.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/035.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/035.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/036.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/036.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/036.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/036.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/037.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/037.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/037.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/037.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/038.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/038.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/038.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/038.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/039.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/039.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/039.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/039.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/040.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/040.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/040.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/040.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/041.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/041.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/041.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/041.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/042.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/042.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/042.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/042.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/043.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/043.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/043.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/043.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/044.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/044.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/044.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/044.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/045.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/045.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/045.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/045.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/046.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/046.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/046.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/046.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/047.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/047.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/047.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/047.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/048.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/048.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/048.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/048.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC259/F/data/049.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC259/F/data/049.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