QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569851#6441. Ancient Magic Circle in TeyvatJWRuixiWA 1ms7988kbC++203.0kb2024-09-17 11:31:102024-09-17 11:31:11

Judging History

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

  • [2024-09-17 11:31:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7988kb
  • [2024-09-17 11:31:10]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

using i128 = __int128;
using pi = pair<int, int>;
using ull = unsigned long long;

IL ostream& operator << (ostream &os, i128 x) {
  static char s[64], *t = s;
  if (x < 0) {
    // os.put('-');
    x = ~(x - 1);
  }
  do {
    *t++ = x % 10 | 48;
    x /= 10;
  } while (x);
  while (t != s) {
    os.put(*--t);
  }
  return os;
}

struct pair_hash {
  ull operator () (const pi &o) const {
    return (ull(o.first) << 32) | o.second;
  }
};


constexpr int N = 1e5 + 9;
constexpr int M = 2e5 + 9;
int n, m, p[N], q[N], d[N];
vi g[N], G[N];

unordered_map<pair<int, int>, int, pair_hash> id;

int cv[N], ce[M], c3, c4, c[N];

IL i128 C (int n, int m) {
  i128 ret = 1;
  L (i, n - m + 1, n) {
    ret *= i;
  }
  L (i, 1, m) {
    ret /= i;
  }
  return ret;
}

int main () {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  L (i, 1, m) {
    int u, v;
    cin >> u >> v;
    id[pi(u, v)] = id[pi(v, u)] = i;
    g[u].eb(v);
    g[v].eb(u);
  }
  L (i, 1, n) {
    p[i] = i, d[i] = sz(g[i]);
  }
  sort(p + 1, p + n + 1, [] (int x, int y) {
    return d[x] < d[y];
  });
  L (i, 1, n) {
    q[p[i]] = i;
  }
  L (u, 1, m) {
    for (int v : g[u]) {
      if (q[v] > q[u]) {
        G[u].eb(v);
      }
    }
  }
  L (i, 1, n) {
    int u = p[i];
    for (int v : G[u]) {
      c[v] = 1;
    }
    for (int v : G[u]) {
      for (int w : G[v]) {
        if (c[w]) {
          c3 += 1;
          cv[u] += 1;
          cv[v] += 1;
          cv[w] += 1;
          ce[id[pi(u, v)]] += 1;
          ce[id[pi(v, w)]] += 1;
          ce[id[pi(w, u)]] += 1;
        }
      }
    }
    for (int v : G[u]) {
      c[v] = 0;
    }
  }
  L (i, 1, n) {
    int u = p[i];
    for (int v : G[u]) {
      for (int w : g[v]) {
        if (q[w] > q[u]) {
          c4 += c[w]++;
        }
      }
    }
    for (int v : G[u]) {
      for (int w : g[v]) {
        c[w] = 0;
      }
    }
  }
  i128 f0 = C(n, 4);
  i128 f1 = m * C(n - 2, 2);
  i128 f2 = C(m, 2);
  L (i, 1, n) {
    f2 += (n - 4) * C(d[i], 2);
  }
  i128 f3 = i128(n - 6) * c3;
  L (i, 1, n) {
    f3 += C(d[i], 3);
  }
  L (u, 1, n) {
    for (int v : G[u]) {
      f3 += i128(d[u] - 1) * (d[v] - 1);
    }
  }
  i128 f4 = c4;
  L (i, 1, n) {
    f4 += i128(d[i] - 2) * cv[i];
  }
  i128 f5 = 0;
  L (i, 1, m) {
    f5 += C(ce[i], 2);
  }
  if (n == 633 && m == 100) {
    cout << f0 << ' ' << f1 << ' ' << f2 << ' ' << f3 << ' ' << f4 << ' ' << f5 << ' ' << c4 << ' ' << c3 << '\n';
  }
  cout << f0 - f1 + f2 - f3 + f4 - f5 << '\n';
}
// I love WHQ!

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

7 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 7684kb

input:

4 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7752kb

input:

4 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

4 2
1 2
1 3

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

4 2
1 2
3 4

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5724kb

input:

4 3
1 2
1 3
1 4

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 0ms
memory: 7764kb

input:

4 3
1 2
2 3
3 4

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 1ms
memory: 7988kb

input:

4 3
1 2
2 3
1 3

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 1ms
memory: 7756kb

input:

4 4
1 2
2 3
1 3
1 4

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

4 4
1 2
2 3
3 4
1 4

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 0ms
memory: 5920kb

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 7704kb

input:

4 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

633 0

output:

6626427570

result:

ok 1 number(s): "6626427570"

Test #14:

score: -100
Wrong Answer
time: 1ms
memory: 7676kb

input:

633 100
284 424
27 560
19 484
92 558
59 385
440 577
11 420
341 543
285 330
430 569
88 259
13 499
444 557
418 483
167 220
185 497
175 489
246 400
387 577
125 303
99 336
152 437
116 324
229 472
200 338
46 197
368 399
345 386
92 439
121 132
50 310
444 525
454 631
174 337
276 337
476 597
405 557
99 263
...

output:

6626427570 19876500 25707 3 0 0 0 0
6606576774

result:

wrong answer 1st numbers differ - expected: '6606576764', found: '6626427570'