0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 15:16:28 +00:00

#1836. 【CTSC2010】星际旅行

https://sjzezoj.com/submission/67611
This commit is contained in:
Baoshuo Ren 2023-01-29 19:50:24 +08:00
parent f1147c9a2d
commit 5277427cb2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 147 additions and 0 deletions

84
S2OJ/1836/1836.cpp Normal file
View File

@ -0,0 +1,84 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 50005;
int n, h[N], son[N], ans[N], res;
std::vector<int> g[N];
void dfs1(int u, int f) {
for (int v : g[u]) {
if (v == f) continue;
dfs1(v, u);
int x = std::min(h[u], h[v]);
h[u] -= x, h[v] -= x;
res += x * 2;
if (h[v]) son[u] = v;
}
}
void dfs2(int u, int f) {
ans[u] = res;
for (int v : g[u]) {
if (v == f) continue;
if (h[u]) {
h[u]--, res++;
dfs2(v, u);
h[u]++, res--;
} else if (son[v]) {
h[son[v]]--, res++;
dfs2(v, u);
h[son[v]]++, res--;
} else {
h[v]++, res--;
dfs2(v, u);
h[v]--, res++;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
h[++x]--, h[++y]--;
g[x].emplace_back(y);
g[y].emplace_back(x);
res += 2;
}
dfs1(1, 0);
dfs2(1, 0);
for (int i = 1; i <= n; i++) {
cout << ans[i] << endl;
}
return 0;
}

BIN
S2OJ/1836/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1836/data/travel9.out (Stored with Git LFS) Normal file

Binary file not shown.