mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
Compare commits
18 Commits
9896659358
...
3256f5c172
Author | SHA1 | Date | |
---|---|---|---|
3256f5c172 | |||
b1f483a26d | |||
39e04e9b16 | |||
9c13898a05 | |||
8f07b5e70f | |||
4a3a25865d | |||
a3280eb4f0 | |||
6da142d5f8 | |||
32ca556536 | |||
78a6e72b66 | |||
0ef4b0e96c | |||
6b06184d03 | |||
320af422bd | |||
58b85e4ba4 | |||
60bd85ed1b | |||
3f348509df | |||
0c3e00a97b | |||
226513485c |
81
BZOJ/1098/1098.cpp
Normal file
81
BZOJ/1098/1098.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, m, cnt, ans[N];
|
||||
std::vector<int> g[N];
|
||||
std::set<int> set;
|
||||
bool vis[N];
|
||||
|
||||
void bfs(int x) {
|
||||
std::queue<int> q;
|
||||
|
||||
set.erase(x);
|
||||
q.push(x);
|
||||
ans[cnt]++;
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
vis[u] = true;
|
||||
|
||||
for (auto it = set.begin(); it != set.end();) {
|
||||
int v = *it;
|
||||
|
||||
if (*std::lower_bound(g[u].begin(), g[u].end(), v) != v) {
|
||||
q.push(v);
|
||||
ans[cnt]++;
|
||||
set.erase(it++);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1, u, v; i <= m; i++) {
|
||||
cin >> u >> v;
|
||||
|
||||
g[u].push_back(v);
|
||||
g[v].push_back(u);
|
||||
}
|
||||
|
||||
std::for_each(g + 1, g + n + 1, [&](auto& v) { std::sort(v.begin(), v.end()); });
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
set.insert(i);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!vis[i]) {
|
||||
cnt++;
|
||||
bfs(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(ans + 1, ans + 1 + cnt);
|
||||
|
||||
cout << cnt << endl;
|
||||
|
||||
for (int i = 1; i <= cnt; i++) {
|
||||
cout << ans[i] << ' ';
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1098/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/14.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/14.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/15.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/15.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1098/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1098/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
126
BZOJ/1391/1391.cpp
Normal file
126
BZOJ/1391/1391.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#pragma GCC optimize("Ofast")
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <queue>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e6 + 5;
|
||||
|
||||
int n, m, s, t, sum;
|
||||
int idx, head[N], edge[N << 1], ver[N << 1], next[N << 1];
|
||||
int dist[N], cur[N];
|
||||
|
||||
void add(int u, int v, int w) {
|
||||
next[idx] = head[u];
|
||||
ver[idx] = v;
|
||||
edge[idx] = w;
|
||||
head[u] = idx++;
|
||||
}
|
||||
|
||||
bool bfs() {
|
||||
memset(dist, 0x00, sizeof(dist));
|
||||
|
||||
std::queue<int> q;
|
||||
|
||||
dist[s] = 1;
|
||||
q.push(s);
|
||||
cur[s] = head[s];
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
|
||||
for (int i = head[u]; ~i; i = next[i]) {
|
||||
int v = ver[i],
|
||||
w = edge[i];
|
||||
|
||||
if (w && !dist[v]) {
|
||||
dist[v] = dist[u] + 1;
|
||||
cur[v] = head[v];
|
||||
|
||||
if (v == t) return true;
|
||||
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int dinic(int u, int limit) {
|
||||
if (u == t) return limit;
|
||||
|
||||
int flow = 0;
|
||||
for (int i = cur[u]; ~i && flow < limit; i = next[i]) {
|
||||
cur[u] = i;
|
||||
|
||||
int v = ver[i],
|
||||
w = edge[i];
|
||||
|
||||
if (w && dist[v] == dist[u] + 1) {
|
||||
int k = dinic(v, std::min(limit - flow, w));
|
||||
|
||||
if (!k) dist[v] = 0;
|
||||
|
||||
edge[i] -= k;
|
||||
edge[i ^ 1] += k;
|
||||
flow += k;
|
||||
}
|
||||
}
|
||||
|
||||
return flow;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
memset(head, 0xff, sizeof(head));
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
s = 0, t = n + m + 1;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x, t;
|
||||
|
||||
cin >> x >> t;
|
||||
|
||||
add(s, i, x);
|
||||
add(i, s, 0);
|
||||
sum += x;
|
||||
|
||||
for (int j = 1; j <= t; j++) {
|
||||
int a, b;
|
||||
|
||||
cin >> a >> b;
|
||||
|
||||
add(i, a + n, b);
|
||||
add(a + n, i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
int y;
|
||||
|
||||
cin >> y;
|
||||
|
||||
add(i + n, t, y);
|
||||
add(t, i + n, 0);
|
||||
}
|
||||
|
||||
int res = 0, flow;
|
||||
while (bfs()) {
|
||||
while (flow = dinic(s, std::numeric_limits<int>::max())) res += flow;
|
||||
}
|
||||
|
||||
cout << sum - res << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1391/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/14.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/14.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/15.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/15.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/16.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/16.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/17.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/17.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/18.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/18.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1391/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1391/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
55
BZOJ/1799/1799.cpp
Normal file
55
BZOJ/1799/1799.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
#include <cstring>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
long long a, b, f[20][200][200], ans;
|
||||
int c[20], p;
|
||||
|
||||
long long dfs(int len, int s, int x, bool limit) {
|
||||
if (s + 9 * len < p) return 0;
|
||||
if (!limit && f[len][s][x] != -1) return f[len][s][x];
|
||||
if (!len) return s == p && x == 0;
|
||||
|
||||
int n = limit ? c[len] : 9;
|
||||
long long res = 0;
|
||||
|
||||
for (int i = 0; i <= n && i + s <= p; i++)
|
||||
res += dfs(len - 1, s + i, (x * 10 + i) % p, limit && (i == c[len]));
|
||||
|
||||
if (!limit) f[len][s][x] = res;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
long long calc(long long x) {
|
||||
int cnt = 0;
|
||||
|
||||
while (x) {
|
||||
c[++cnt] = x % 10;
|
||||
x /= 10;
|
||||
}
|
||||
|
||||
long long res = 0;
|
||||
|
||||
for (p = 1; p <= cnt * 9; p++) {
|
||||
memset(f, 0xff, sizeof(f));
|
||||
res += dfs(cnt, 0, 0, 1);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> a >> b;
|
||||
|
||||
cout << calc(b) - calc(a - 1) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1799/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1799/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1799/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
81
BZOJ/1827/1827.cpp
Normal file
81
BZOJ/1827/1827.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, sum, root, c[N], siz[N], max_siz[N], dep[N];
|
||||
long long ans;
|
||||
std::vector<std::pair<int, int>> g[N];
|
||||
|
||||
void dfs1(int u, int f) {
|
||||
siz[u] = c[u];
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
w = e.second;
|
||||
|
||||
if (v == f) continue;
|
||||
|
||||
dfs1(v, u);
|
||||
|
||||
siz[u] += siz[v];
|
||||
max_siz[u] = std::max(max_siz[u], siz[v]);
|
||||
}
|
||||
|
||||
max_siz[u] = std::max(max_siz[u], sum - siz[u]);
|
||||
}
|
||||
|
||||
void dfs2(int u, int f) {
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
w = e.second;
|
||||
|
||||
if (v == f) continue;
|
||||
|
||||
dep[v] = dep[u] + w;
|
||||
dfs2(v, u);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> c[i];
|
||||
|
||||
sum += c[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);
|
||||
}
|
||||
|
||||
dfs1(1, 0);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!root || max_siz[i] < max_siz[root]) {
|
||||
root = i;
|
||||
}
|
||||
}
|
||||
|
||||
dep[0] = -1;
|
||||
dfs2(root, 0);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans += static_cast<long long>(c[i]) * dep[i];
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1827/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1827/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1827/data/4.out
(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