提出 #74713943


ソースコード 拡げる

#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define drep(i, x, y) for (int i = x; i >= y; --i)
#define ll long long
#define pb emplace_back
#define pii pair<int, int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 300005;
const int mod = 998244353;
inline ll qp(ll a, ll b = mod - 2) {
	ll s = 1;
	for(; b; b >>= 1, a = a * a % mod)
		if(b & 1) s = s * a % mod; return s;
}

vector<int> G[N];
int sz[N], n;
ll ans, k;
inline void dfs(int u, int fa) {
    sz[u] = 1;
    for(int v : G[u]) {
        if(v == fa) continue;
        dfs(v, u);
        sz[u] += sz[v];
        ans = (ans + (ll)sz[v] * (n - sz[v])) % mod;
    }
}
inline ll F(int x) { return (ll)(x - 1) * x % mod * (x + 1) % mod; }
inline void solve() {
	cin >> n >> k;
    rep(i, 1, n) G[i].clear();
    rep(i, 2, n) {
        int u, v; cin >> u >> v;
        G[u].pb(v), G[v].pb(u);
    }
	ans = 0, dfs(1, 0);
	ans = ans * F(n + k) % mod * qp(F(n)) % mod;
    cout << ans << '\n';
}
int main() {
	fastio;
    int T; cin >> T;
    while(T--) solve();
    return 0;
}

提出情報

提出日時
問題 E - Tree Growing
ユーザ AyaseSaki
言語 C++23 (GCC 15.2.0)
得点 900
コード長 1236 Byte
結果 AC
実行時間 88 ms
メモリ 29912 KiB

コンパイルエラー

./Main.cpp: In function 'long long int qp(long long int, long long int)':
./Main.cpp:17:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   17 |                 if(b & 1) s = s * a % mod; return s;
      |                 ^~
./Main.cpp:17:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   17 |                 if(b & 1) s = s * a % mod; return s;
      |                                            ^~~~~~
./Main.cpp:16:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 |         for(; b; b >>= 1, a = a * a % mod)
      |         ^~~
./Main.cpp:17:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   17 |                 if(b & 1) s = s * a % mod; return s;
      |                                            ^~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 1
AC × 32
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 2 ms 3456 KiB
01_handmade_00.txt AC 2 ms 3576 KiB
01_handmade_01.txt AC 32 ms 3516 KiB
01_handmade_02.txt AC 88 ms 29912 KiB
01_handmade_03.txt AC 76 ms 24216 KiB
01_handmade_04.txt AC 43 ms 22076 KiB
02_random_00.txt AC 74 ms 21392 KiB
02_random_01.txt AC 74 ms 21276 KiB
02_random_02.txt AC 74 ms 21240 KiB
02_random_03.txt AC 74 ms 21364 KiB
02_random_04.txt AC 73 ms 21324 KiB
02_random_05.txt AC 74 ms 21324 KiB
02_random_06.txt AC 69 ms 21420 KiB
02_random_07.txt AC 71 ms 21476 KiB
02_random_08.txt AC 69 ms 21492 KiB
02_random_09.txt AC 71 ms 21528 KiB
02_random_10.txt AC 69 ms 21376 KiB
02_random_11.txt AC 69 ms 21340 KiB
02_random_12.txt AC 21 ms 3416 KiB
02_random_13.txt AC 21 ms 3576 KiB
02_random_14.txt AC 24 ms 4156 KiB
02_random_15.txt AC 41 ms 7064 KiB
02_random_16.txt AC 80 ms 24892 KiB
02_random_17.txt AC 76 ms 21620 KiB
02_random_18.txt AC 75 ms 21420 KiB
02_random_19.txt AC 75 ms 21368 KiB
02_random_20.txt AC 79 ms 24888 KiB
02_random_21.txt AC 81 ms 27732 KiB
02_random_22.txt AC 75 ms 23228 KiB
02_random_23.txt AC 82 ms 28792 KiB
02_random_24.txt AC 81 ms 25332 KiB
02_random_25.txt AC 79 ms 26136 KiB