0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:08:47 +00:00

3522. [POI2014]Hotel

https://hydro.ac/d/bzoj/record/6322aadfbdf9bc31d1605fa0
This commit is contained in:
Baoshuo Ren 2022-09-15 12:33:33 +08:00
parent 3f348509df
commit 60bd85ed1b
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
13 changed files with 100 additions and 0 deletions

64
BZOJ/3522/3522.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5005;
int n, max_dep;
long long ans;
std::vector<int> g[N];
std::array<int, N> f1, f2, cnt;
void dfs(int u, int f, int d) {
cnt[d]++;
max_dep = std::max(max_dep, d);
for (int v : g[u]) {
if (v == f) continue;
dfs(v, u, d + 1);
}
}
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;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
dfs(1, 0, 1);
for (int i = 1; i <= n; i++) {
std::fill(f1.begin(), f1.end(), 0);
std::fill(f2.begin(), f2.end(), 0);
for (int u : g[i]) {
max_dep = 0;
std::fill(cnt.begin(), cnt.end(), 0);
dfs(u, i, 1);
for (int j = 1; j <= max_dep; j++) {
ans += f1[j] * cnt[j];
f1[j] += f2[j] * cnt[j];
f2[j] += cnt[j];
}
}
}
cout << ans << endl;
return 0;
}

BIN
BZOJ/3522/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3522/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.