mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:11:58 +00:00
parent
4db607fadb
commit
f1bda00a3d
64
LibreOJ/2431/2431.cpp
Normal file
64
LibreOJ/2431/2431.cpp
Normal 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
LibreOJ/2431/data/hot0.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot0.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot0.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot0.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot10a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot10a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot10a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot10a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot10b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot10b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot10b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot10b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1c.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1c.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1c.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1c.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1d.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1d.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1d.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1d.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1e.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1e.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot1e.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot1e.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot2a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot2a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot2a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot2a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot2b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot2b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot2b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot2b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot3a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot3a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot3a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot3a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot3b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot3b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot3b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot3b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot4a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot4a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot4a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot4a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot4b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot4b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot4b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot4b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot5a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot5a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot5a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot5a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot5b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot5b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot5b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot5b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot6a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot6a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot6a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot6a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot6b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot6b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot6b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot6b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot7a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot7a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot7a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot7a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot7b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot7b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot7b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot7b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot8a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot8a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot8a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot8a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot8b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot8b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot8b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot8b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot9a.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot9a.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot9a.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot9a.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot9b.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot9b.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2431/data/hot9b.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2431/data/hot9b.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user