QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685548 | #9530. A Game On Tree | fgz | Compile Error | / | / | C++23 | 3.7kb | 2024-10-28 20:03:44 | 2024-10-28 20:03:45 |
Judging History
This is the latest submission verdict.
- [2024-10-28 20:03:45]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-10-28 20:03:44]
- Submitted
answer
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0), cin.tie(0)
#define time chrono::system_clock::now().time_since_epoch().count()
using namespace std;
#define int long long
using ll = long long;
using pll = pair<int, int>;
const int mod = 998244353, N = 2e5 + 10;
int qmi(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
using int64_t = long long;
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while(n){
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<mod>;
void solve(){
int n; cin >> n;
vector edg(n + 10, vector<int>());
for (int i = 1; i < n; i ++) {
int u, v; cin >> u >> v;
edg[u].push_back(v);
edg[v].push_back(u);
}
vector<mint> sz(n + 10, 0);
vector<mint> sum(n + 10, 0), tot(n + 10, 0);
mint res = 0;
function<void(int, int)> dfs1 = [&] (int u, int p) {
sz[u] = 1;
for (auto v : edg[u]) {
if (v == p) continue;
dfs1(v, u);
sz[u] += sz[v];
sum[u] = sum[u] + sz[v] * sz[v];
tot[u] += sum[v];
}
sum[u] = sum[u] + sz[u] * sz[u];
};
function<void(int, int)> dfs2 = [&] (int u, int p) {
for (auto v : edg[u]) {
if (p == v) continue;
res += sz[v] * sz[v] * (n - sz[v]) * (n - sz[v]);
res += 2 * (n - sz[v]) * (n - sz[v]) * (sum[v] - sz[v] * sz[v]);
res += sum[v] * (tot[u] - sum[v]);
dfs2(v, u);
}
};
dfs1(1, 0);
dfs2(1, 0);
int t = n * n % mod * (n - 1) % mod * (n - 1) % mod * qmi(4, mod - 2) % mod;
res = res * qmi(t, mod - 2);
cout << res << '\n';
}
signed main()
{
ios;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
answer.code:21:7: error: conflicting declaration ‘using int64_t = long long int’ 21 | using int64_t = long long; | ^~~~~~~ In file included from /usr/include/x86_64-linux-gnu/sys/types.h:155, from /usr/include/stdlib.h:394, from /usr/include/c++/13/cstdlib:79, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42, from answer.code:1: /usr/include/x86_64-linux-gnu/bits/stdint-intn.h:27:19: note: previous declaration as ‘typedef __int64_t int64_t’ 27 | typedef __int64_t int64_t; | ^~~~~~~