mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 19:48:51 +00:00
parent
394dec7271
commit
9df23296c0
106
LibreOJ/3250/3250.cpp
Normal file
106
LibreOJ/3250/3250.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e5 + 5;
|
||||
|
||||
int n, c1[N], c2[N], c[N];
|
||||
long long ans;
|
||||
int id[N], rid[N], fa[N], dep[N], siz[N], son[N], top[N];
|
||||
std::vector<std::pair<int, int>> g[N];
|
||||
|
||||
void dfs1(int u, int f) {
|
||||
fa[u] = f;
|
||||
dep[u] = dep[f] + 1;
|
||||
siz[u] = 1;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first;
|
||||
|
||||
if (v == f) continue;
|
||||
|
||||
dfs1(v, u);
|
||||
siz[u] += siz[v];
|
||||
|
||||
if (siz[son[u]] < siz[v]) son[u] = v;
|
||||
}
|
||||
}
|
||||
|
||||
void dfs2(int u, int t) {
|
||||
static int cnt = 0;
|
||||
|
||||
rid[id[u] = ++cnt] = u;
|
||||
top[u] = t;
|
||||
|
||||
if (son[u]) dfs2(son[u], t);
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first;
|
||||
|
||||
if (v == fa[u] || v == son[u]) continue;
|
||||
|
||||
dfs2(v, v);
|
||||
}
|
||||
}
|
||||
|
||||
int lca(int u, int v) {
|
||||
while (top[u] != top[v]) {
|
||||
if (dep[top[u]] < dep[top[v]]) std::swap(u, v);
|
||||
u = fa[top[u]];
|
||||
}
|
||||
|
||||
return dep[u] < dep[v] ? u : v;
|
||||
}
|
||||
|
||||
void dfs3(int u) {
|
||||
int fa_edge_id = 0;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
id = e.second;
|
||||
|
||||
if (v == fa[u]) {
|
||||
fa_edge_id = id;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
dfs3(v);
|
||||
|
||||
c[u] += c[v];
|
||||
}
|
||||
|
||||
ans += std::min<long long>(static_cast<long long>(c1[fa_edge_id]) * c[u], c2[fa_edge_id]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1, u, v; i < n; i++) {
|
||||
cin >> u >> v >> c1[i] >> c2[i];
|
||||
|
||||
g[u].emplace_back(v, i);
|
||||
g[v].emplace_back(u, i);
|
||||
}
|
||||
|
||||
dfs1(1, 1);
|
||||
dfs2(1, 1);
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
c[i]++, c[i + 1]++;
|
||||
c[lca(i, i + 1)] -= 2;
|
||||
}
|
||||
|
||||
dfs3(1);
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
LibreOJ/3250/data/putovanje.in.0a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.0a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.0b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.0b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.0c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.0c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.1i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.1i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2j
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2j
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2k
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2k
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.2l
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.2l
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.in.3j
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.in.3j
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.0a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.0a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.0b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.0b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.0c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.0c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.1i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.1i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2j
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2j
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2k
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2k
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.2l
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.2l
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3a
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3a
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3b
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3b
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3c
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3c
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3d
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3d
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3e
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3e
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3f
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3f
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3g
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3g
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3h
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3h
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3i
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3i
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3250/data/putovanje.out.3j
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3250/data/putovanje.out.3j
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user