QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710476#9530. A Game On TreemitthuWA 0ms4064kbC++141.7kb2024-11-04 20:00:532024-11-04 20:00:53

Judging History

This is the latest submission verdict.

  • [2024-11-04 20:00:53]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 4064kb
  • [2024-11-04 20:00:53]
  • Submitted

answer

#include<bits/stdc++.h>
const int maxn = 1e5 + 5;
const int mo = 998244353;
using namespace std;
int T, n, head[maxn], tot;
int siz[maxn], sum[maxn], ans, pw[maxn];
struct edge{
    int v, nxt;
}e[maxn << 1];
int ksm(int x, int y){
    int res = 1;
    for (; y; y >>= 1, x = 1LL * x * x % mo)
        if(y & 1) res = 1LL * res * x % mo;
    return res;
}
void add(int u, int v){
    e[++tot] = {v, head[u]}; head[u] = tot;
}
void dfs(int u, int fa){
    siz[u] = 1; sum[u] = 0;
    int res = 0;
    for (int i = head[u]; i; i = e[i].nxt){
        int v = e[i].v;
        if(v == fa)continue;
        dfs(v, u);
        siz[u] += siz[v];
        res = (res + sum[v])%mo;
        sum[u] = (sum[u] + sum[v]) % mo;     
        ans = (ans + 1LL * pw[n - siz[v]] * pw[siz[v]] % mo) % mo;  
    }
    for (int i = head[u]; i; i = e[i].nxt){
        int v = e[i].v;
        if(v == fa) continue;
        ans = (ans + 2LL * pw[n - siz[v]] * (sum[v] - pw[siz[v]] + mo) % mo) % mo;
        ans = (ans + 1LL * sum[v] * (res - sum[v] + mo) % mo) % mo;
    }
    sum[u] = (sum[u] + pw[siz[u]]) % mo;
}
void solve(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)head[i] = 0; 
    tot = ans = 0;
    for (int i = 1, u, v; i < n; i++){
        scanf("%d %d", &u, &v);
        add(u, v); add(v, u);
    }
    dfs(1, 0);
    int x = ksm(n, mo - 2), y = ksm(n - 1, mo - 2);
    x = 1LL * x * x % mo; y = 1LL * y * y % mo;
    ans = 4LL * ans * x % mo * y % mo;
    printf("%d\n", ans);
}
int main(){
    freopen("1.in", "r", stdin);
    scanf("%d", &T);
    for (int i = 1; i <= 1e5; i++)pw[i] = 1LL * i * i % mo;
    for (; T; T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4064kb

input:

2
3
1 2
2 3
5
1 2
1 5
3 2
4 2

output:


result:

wrong answer 1st lines differ - expected: '443664158', found: ''