QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693526#9530. A Game On Treerxzfn639Compile Error//C++232.3kb2024-10-31 16:20:012024-10-31 16:20:11

Judging History

This is the latest submission verdict.

  • [2024-10-31 16:20:11]
  • Judged
  • [2024-10-31 16:20:01]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
template<typename T> 
T qpow(T x, i64 n) 
{
    T ans = 1;
    while(n) {
        if(n & 1) {
            ans *= x;
        }
        x *= x; n >>= 1;
    }
    return ans;
}

struct MInt 
{
    int x;
    constexpr MInt(): x(0) {}
    constexpr MInt(int x): x(x) {}
    constexpr MInt(i64 x): x(x) {}
    constexpr int norm(int x) {
        if(x >= P) x -= P;
        if(x < 0) x += P;
        return x;
    }
    constexpr MInt operator+=(const MInt o) { return x = norm(x+o.x), *this; }
    constexpr MInt operator-=(const MInt o) { return x = norm(x-o.x), *this; }
    constexpr MInt operator*=(const MInt o) { return x = 1ll * x * o.x, *this; }
    constexpr MInt operator/=(const MInt o) { return *this *= o.inv(); }
    friend constexpr MInt operator+(const MInt a, const MInt b) { MInt res(a); return res += b; }
    friend constexpr MInt operator-(const MInt a, const MInt b) { MInt res(a); return res -= b; }
    friend constexpr MInt operator*(const MInt a, const MInt b) { MInt res(a); return res *= b; }
    friend constexpr MInt operator/(const MInt a, const MInt b) { MInt res(a); return res /= b; }
    constexpr MInt inv() const { return qpow(*this, P - 2); }
    constexpr int val() const { return x; }
};

using Z = MInt;
void solve() {
    int n;
    cin >> n;
    vector<vector<int>> G(n + 1);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<Z> sz(n + 1), sum(n + 1);
    Z ans = 0;
    auto dfs = [&](auto self, int u, int fa) -> void {
        sz[u] = 1;
        for (auto v : G[u]) {
            if (v == fa) continue;
            self(self, v, u);
            sz[u] += sz[v];
            ans = (ans + (n - sz[v]) * (n - sz[v]) * sz[v] * sz[v]);
            ans = (ans + 2 * sum[u] * sum[v]);
            sum[u] = (sum[u] + sum[v]);
        }
        ans = (ans + 2 * (n - sz[u]) * (n - sz[u]) * sum[u]);
        sum[u] = (sum[u] + sz[u] * sz[u]);
    };
    dfs(dfs, 1, 0);
    Z m = (n * (n - 1) / 2);
    ans = ans * qpow(m * m, P - 2);
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1; 
    cin >> t;
    while(t--) solve();
    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:70:10: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘Z’ {aka ‘MInt’})
   70 |     cout << ans << '\n';
      |     ~~~~ ^~ ~~~
      |     |       |
      |     |       Z {aka MInt}
      |     std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/13/bits/unique_ptr.h:42,
                 from /usr/include/c++/13/memory:78,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from answer.code:1:
/usr/include/c++/13/ostream:110:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  110 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/13/ostream:110:36: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)’ {aka ‘std::basic_ostream<char>& (*)(std::basic_ostream<char>&)’}
  110 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/ostream:119:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]’
  119 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/13/ostream:119:32: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)’ {aka ‘std::basic_ios<char>& (*)(std::basic_ios<char>&)’}
  119 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/ostream:129:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  129 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/13/ostream:129:30: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘std::ios_base& (*)(std::ios_base&)’
  129 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/13/ostream:168:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  168 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/13/ostream:168:23: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘long int’
  168 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/13/ostream:172:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  172 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/13/ostream:172:32: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘long unsigned int’
  172 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/13/ostream:176:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  176 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/13/ostream:176:23: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘bool’
  176 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/13/ostream:880:
/usr/include/c++/13/bits/ostream.tcc:96:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]’
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from ‘Z’ {aka ‘MInt’} to ‘short int’
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/13/ostream:183:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsig...