結果

問題 No.3373 Partial Complement Tree
コンテスト
ユーザー 👑 loop0919
提出日時 2025-10-30 22:49:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 3,009 ms
コンパイル使用メモリ 283,952 KB
実行使用メモリ 16,596 KB
最終ジャッジ日時 2025-11-21 20:52:08
合計ジャッジ時間 6,035 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;

using mint = atcoder::modint998244353;

void solve() {
    int N;
    cin >> N;

    vector<vector<int>> G(N);
    vector<pair<int, int>> edges(N - 1);
    for (int i = 0; i < N - 1; i++) {
        int U, V;
        cin >> U >> V;
        
        G[U - 1].push_back(V - 1);
        G[V - 1].push_back(U - 1);
        edges[i] = make_pair(U - 1, V - 1);
    }

    mint ans = 0;
    for (auto &[u, v]: edges) {
        ans += mint(G[u].size() - 1) * mint(G[v].size() - 1);
    }

    cout << ans.val() << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int T;
    cin >> T;

    while (T--) solve();
}
0