QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684238 | #9530. A Game On Tree | Symmetree | Compile Error | / | / | C++17 | 1.6kb | 2024-10-28 11:40:00 | 2024-10-28 11:40:00 |
Judging History
This is the latest submission verdict.
- [2024-10-28 11:40:00]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-10-28 11:40:00]
- Submitted
answer
#include<bits/stdc++.h>
const int N = 1e5+5, mod = 998244353;
struct Edge{int v, ne;} edge[N<<1];
#define v(x) edge[x].v
#define ne(x) edge[x].ne
int n, x, y, tot, head[N], siz[N], ssiz2[N], ans;
void addline(int u, int v) {
edge[++tot] = {v, head[u]}, head[u] = tot;
}
void upd(int &a, int b) {
a += b, a %= mod;
}
int calc(int x) {
return 1ll * x * x % mod;
}
void dfs1(int x, int fa) {
siz[x] = 1;
for(int i = head[x]; ~i; i = ne(i)) {
int y =v(i);
if(y == fa) continue;
dfs1(y, x), siz[x] += siz[y], upd(ssiz2[x], ssiz2[y]);
}
upd(ssiz2[x], calc(siz[x]));
}
void dfs2(int x, int fa, int ssizsum, int nsizsum) {
upd(ans, 1ll * calc(siz[x]) * ssizsum % mod);
upd(ans, 1ll * calc(siz[x]) * nsizsum % mod);
upd(ans ,1ll * calc(n - siz[x]) * (ssiz2[x] - calc(siz[x]) + mod) % mod);
for(int i = head[x]; ~i; i = ne(i)) {
int y = v(i);
if(y == fa) continue;
dfs2(y, x, (ssizsum + ssiz2[x] - ssiz2[y] - calc(siz[x]) + 2 * mod) % mod,
(nsizsum + calc(n - siz[y])) % mod);
}
}
int ksm(int a, int b) {
int ans = 1;
for(; b; b >>= 1, a = 1ll * a * a % mod) if(b & 1) ans = 1ll * ans * a % mod;
return ans;
}
void solve() {
scanf("%d", &n), tot = ans = 0;
for(int i = 1; i <= n; ++i) siz[i] = 1, ssiz2[i] = 0, head[i] = -1;
for(int i = 1; i < n; ++i) {
scanf("%d%d", &x, &y);
addline(x, y), addline(y, x);
}
dfs1(1, 0), dfs2(1, 0, 0, 0);
int num = 1l * n * (n - 1) / 2 % mod;
ans = 1ll * ans * ksm(calc(num), mod - 2) mod;
printf("%d\n", ans);
}
signed main() {
int t;
scanf("%d", &t);
while(t--) solve();
return 0;
}
详细
answer.code: In function ‘void solve()’: answer.code:50:50: error: expected ‘;’ before ‘mod’ 50 | ans = 1ll * ans * ksm(calc(num), mod - 2) mod; | ^ ~~~ | ; answer.code:42:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | scanf("%d", &n), tot = ans = 0; | ~~~~~^~~~~~~~~~ answer.code:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d%d", &x, &y); | ~~~~~^~~~~~~~~~~~~~~~ answer.code: In function ‘int main()’: answer.code:56:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf("%d", &t); | ~~~~~^~~~~~~~~~