QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756170#1. I/O TestbaoyangawaCompile Error//C++142.9kb2024-11-16 19:13:212024-11-16 19:13:21

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 19:13:21]
  • 评测
  • [2024-11-16 19:13:21]
  • 提交

config.txt


input_test

#include <bits/stdc++.h>
#define frr(a) freopen(a, "r", stdin)
#define fww(a) freopen(a, "w", stdout)
#define eb emplace_back
using namespace std;
using ll = long long;
struct fio {
    char gc() {return getchar();}
    template <typename T> void read(T& x) {
        cin >> x; return;
        char c = gc(), l = 0; x = 0;
        while (!isdigit(c)) l = c, c = gc();
        while ( isdigit(c)) x = (x << 1) + (x << 3) + c - 48, c = gc();
        if (l == '-') x = -x;
    }
    template <typename T, typename ...A> void read(T& x, A&... a) {
        read(x), read(a...);
    }
} IO;
const int N = 2e5 + 10, mod = 998244353;
ll qpow(ll a, ll n = mod - 2) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod, n >>= 1;
    } return res;
}
struct ED {
    ll v, nxt;
    ED(int a = 0, int b = 0) {
        v = a, nxt = b;
    }
} edge[2 * N]; int head[N], tote;
void adde(ll u, ll v) {
    edge[++tote] = ED(v, head[u]);
    head[u] = tote;
}
ll n;
ll dep[N], fa[N];
void clr() {
    for (int i = 0; i <= n; i++) {
        dep[i] = fa[i] = head[i] = 0;
    } 
    for (int i = 1; i <= tote; i++) edge[i] = ED();
    tote = 0;
}
void dfs1(int x = 1, int fat = 0) {
    dep[x] = dep[fat] + 1; fa[x] = fat;
    ll S = 0;
    for (int i = head[x]; i; i = edge[i].nxt) {
        int y = edge[i].v; if (y == fat) continue;
        dfs1(y, x);
    } 
}
ll res = 0;
int F[N];
void add(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    while (dep[u] > dep[v]) {
        F[u] = 1; u = fa[u];
    } if (u == v) return;
    while (u != v) {
        F[u] = 1, F[v] = 1;
        u = fa[u], v = fa[v];
    } return;
}
ll cnt(int u, int v) {
    ll res = 0;
    if (dep[u] < dep[v]) swap(u, v);
    while (dep[u] > dep[v]) {
        res += F[u]; u = fa[u];
    } if (u == v) return res * res;
    while (u != v) {
        res += F[u] + F[v];
        u = fa[u], v = fa[v];
    } return res * res;
}
void solve() {
    res = 0;
    IO.read(n);
    for (int i = 1; i < n; i++) {
        int u, v; IO.read(u, v);
        adde(u, v), adde(v, u);
    }
    dfs1();
    for (int u = 1; u <= n; u++) {
        for (int v = u + 1; v <= n; v++) {
            for (int i = 1; i <= n; i++) F[i] = 0;
            add(u, v);
            for (int x = 1; x <= n; x++) {
                for (int y = x + 1; y <= n; y++) {
                    ll val = cnt(x, y);
                    // printf("[%d %d] [%d %d] : %lld\n", u, v, x, y, val);
                    (res += val) %= mod;
                }
            }
        }
    }
    ll mu = (n * (n - 1) / 2ll) % mod; mu = qpow(mu * mu % mod);
    res = res * mu % mod;
    printf("%lld\n", res);
    clr();
}
int main() {
    // frr("1.in");
    // fww("1.ans");
    int Ts; IO.read(Ts);
    while (Ts--) solve();
    return 0;
}
/*
2
3
1 2
2 3
5
1 2
1 5
3 2
4 2

*/

output_test


详细

Invalid Configuration File: failed to read Nin and Nout