結果
| 問題 |
No.3350 Tree and Two Apples
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-13 22:37:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,190 bytes |
| コンパイル時間 | 3,507 ms |
| コンパイル使用メモリ | 291,136 KB |
| 実行使用メモリ | 16,384 KB |
| 最終ジャッジ日時 | 2025-11-13 22:38:21 |
| 合計ジャッジ時間 | 8,512 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 WA * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#define pb push_back
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector<T> vec) {
o << "{"; int f = 0;
for (T i : vec) o << (f++ ? " " : "") << i;
return o << "}";
}
void bug__(int c, auto ...a) {
cerr << "\e[1;" << c << "m";
(..., (cerr << a << " "));
cerr << "\e[0m" << endl;
}
#define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x)
#define bug(x...) bug_(32, x)
#define bugv(x...) bug_(36, vector(x))
#define safe bug_(33, "safe")
#else
#define bug(x...) void(0)
#define bugv(x...) void(0)
#define safe void(0)
#endif
const int mod = 998244353, N = 200087;
typedef unsigned long long ull;
ull seed = 56562;
ull shift(ull x) {
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return x;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
vector <vector <int>> adj(n);
for (int i = 0, u, v; i < n - 1; ++i) {
cin >> u >> v, --u, --v;
adj[u].pb(v), adj[v].pb(u);
}
vector <ull> down(n), up(n), cur(n);
auto dfs = [&](auto self, int v, int pa) -> void {
down[v] = seed;
for (int u : adj[v]) if (u != pa) {
self(self, u, v);
down[v] += shift(down[u]);
}
};
auto dfs2 = [&](auto self, int v, int pa) -> void {
ull tmp = seed;
tmp += shift(up[v]);
for (int u : adj[v]) if (u != pa) {
tmp += shift(down[u]);
}
for (int u : adj[v]) if (u != pa) {
tmp -= shift(down[u]);
up[u] = tmp;
self(self, u, v);
tmp += shift(down[u]);
}
};
dfs(dfs, 0, -1);
dfs2(dfs2, 0, -1);
for (int i = 0; i < n; ++i) {
if (i) cur[i] = down[i] + shift(up[i]);
else cur[i] = down[i];
}
map <ull, int> cnt;
for (int i = 0; i < n; ++i) {
bug(cur[i]);
cnt[cur[i]]++;
}
ll ans = 1ll * sz(cnt) * sz(cnt);
for (auto [x, y] : cnt) {
if (y > 1) ans++;
}
cout << ans << "\n";
}