結果

問題 No.1507 Road Blocked
ユーザー だれだれ
提出日時 2021-05-14 23:36:10
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,146 bytes
コンパイル時間 2,825 ms
使用メモリ 14,420 KB
最終ジャッジ日時 2022-11-25 23:08:51
合計ジャッジ時間 6,994 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
5,836 KB
testcase_01 AC 3 ms
5,772 KB
testcase_02 AC 3 ms
5,768 KB
testcase_03 AC 68 ms
14,420 KB
testcase_04 AC 78 ms
9,828 KB
testcase_05 AC 79 ms
9,844 KB
testcase_06 AC 78 ms
9,848 KB
testcase_07 AC 82 ms
9,828 KB
testcase_08 AC 81 ms
9,776 KB
testcase_09 AC 76 ms
9,792 KB
testcase_10 AC 77 ms
9,816 KB
testcase_11 AC 74 ms
9,720 KB
testcase_12 AC 80 ms
9,768 KB
testcase_13 AC 79 ms
9,768 KB
testcase_14 AC 79 ms
9,788 KB
testcase_15 AC 76 ms
9,892 KB
testcase_16 AC 82 ms
9,800 KB
testcase_17 AC 83 ms
9,788 KB
testcase_18 AC 85 ms
9,820 KB
testcase_19 AC 80 ms
9,728 KB
testcase_20 AC 73 ms
9,820 KB
testcase_21 AC 76 ms
9,772 KB
testcase_22 AC 72 ms
9,728 KB
testcase_23 AC 81 ms
9,868 KB
testcase_24 AC 82 ms
9,724 KB
testcase_25 AC 83 ms
9,792 KB
testcase_26 AC 77 ms
9,772 KB
testcase_27 AC 76 ms
9,724 KB
testcase_28 AC 75 ms
9,772 KB
testcase_29 AC 73 ms
9,824 KB
testcase_30 AC 73 ms
9,788 KB
testcase_31 AC 80 ms
9,848 KB
testcase_32 AC 78 ms
9,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

using mint = modint998244353;
vector<int> edge[100010];

i64 dp[100010];

int dfs(int now, int p)
{
    dp[now] = 1;
    for (auto e: edge[now])
    {
        if (e == p) continue;
        dp[now] += dfs(e, now);
    }
    return dp[now];
}

int main()
{
    int n;
    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(0, -1);
    mint ans = n;
    ans *= n - 1;
    ans *= n - 1;
    rep(i, n)
    {
        ans -= dp[i] * (n - dp[i]);
    }
    ans /= n;
    ans /= n - 1;
    ans /= n - 1;
    ans *= 2;
    ans -= 1;
    cout << ans.val() << endl;
}
0