結果
| 問題 |
No.3373 Partial Complement Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-21 22:10:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 115 ms / 2,000 ms |
| コード長 | 1,107 bytes |
| コンパイル時間 | 3,968 ms |
| コンパイル使用メモリ | 255,540 KB |
| 実行使用メモリ | 19,192 KB |
| 最終ジャッジ日時 | 2025-11-21 22:10:24 |
| 合計ジャッジ時間 | 6,654 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using isize = size_t;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using f64 = long double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(3);
_main();
}
i32 pow(i32 x, i32 n) {
i32 res = 1;
i32 a = x;
while (n > 0) {
if (n & 1) res *= a;
a *= a;
n >>= 1;
}
return res;
}
void _main() {
i64 t;
cin >> t;
for (;t--;) {
i64 n;
cin >> n;
mint ans = 0;
vector<vector<i64>> g(n);
vector<p2> edge(n - 1);
for (i64 i = 0; i < n - 1; i++) {
i64 u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
edge[i] = {u, v};
}
for (auto [u, v] : edge) {
i64 x = g[u].size(), y = g[v].size();
x--, y--;
ans += x * y;
}
cout << ans.val() << "\n";
}
}