QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569857#6441. Ancient Magic Circle in TeyvatJWRuixiWA 2ms8100kbC++202.8kb2024-09-17 11:33:292024-09-17 11:33:30

Judging History

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

  • [2024-09-17 11:33:30]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8100kb
  • [2024-09-17 11:33:29]
  • 提交

answer

#include <bits/stdc++.h>
#define eb emplace_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define int long long

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tu;
bool Mbe;

const int N = 1e5 + 100;
const int M = 2e5 + 200;

int n, m, l3, c3, c4;
int op[10], d[N], ct[N], cte[M], vs[N];
vector<pi> g[N], h[N];

void solve() {
    cin >> n >> m;
    for (int i = 1, u, v; i <= m; i++) 
        cin >> u >> v, g[u].eb(v, i), g[v].eb(u, i), d[u]++, d[v]++;
    for (int u = 1; u <= n; u++) {
        for (pi p : g[u]) {
            int v = p.fi, w = p.se;
            if (d[u] > d[v] || (d[u] == d[v] && u > v)) h[u].eb(v, w);
        }
    }
    for (int u = 1; u <= n; u++) {
        for (pi p : h[u]) {
            int v = p.fi;
            for (pi q : g[v]) {
                int w = q.fi;
                if (d[u] < d[w] || (d[u] == d[w] && u <= w)) continue;
                c4 += (ct[w]++);
            }
        }
        for (pi p : h[u]) 
            for (pi q : g[p.fi]) ct[q.fi] = 0;
    }
    for (int u = 1; u <= n; u++) {
        for (pi p : h[u]) vs[p.fi] = p.se;
        for (pi p : h[u]) {
            int v = p.fi, i = p.se;
            for (pi q : h[v]) {
                int w = q.fi, j = q.se;
                if (!vs[w]) continue;
                c3++, ct[u]++, ct[v]++, ct[w]++;
                cte[i]++, cte[j]++, cte[vs[w]]++;
            }
        }
        for (pi p : h[u]) vs[p.fi] = 0;
    }
    for (int i = 1; i <= n; i++)
        l3 += d[i] * (d[i] - 1) / 2;
    op[0] = (__int128)n * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4;
    op[1] = m * (n - 2) * (n - 3) / 2;
    op[2] = (n - 3) * l3 + m * (m - 1) / 2 - l3;
    op[3] = (n - 3) * c3;
    for (int i = 1; i <= n; i++) op[3] += d[i] * (d[i] - 1) * (d[i] - 2) / 6;
    for (int i = 1; i <= n; i++) {
        for (pi p : g[i]) {
            int j = p.fi;
            if (i < j) op[3] += (d[i] - 1) * (d[j] - 1);
        }
    }
    op[3] -= 3 * c3;
    op[4] = c4;
    for (int i = 1; i <= n; i++) op[4] += ct[i] * (d[i] - 2);
    for (int i = 1; i <= n; i++) {
        for (pi p : g[i]) {
            int j = p.fi;
            if (i < j) op[5] += cte[p.se] * (cte[p.se] - 1) / 2;
        }
    }
		if (n == 633 && m == 100) {
			cout << op[0] << ' ' << op[1] << ' ' << op[2] << ' ' << op[3] << ' ' << op[4] << ' ' << op[5] << '\n';
		}
    cout << abs(op[0] - op[1] + op[2] - op[3] + op[4] - op[5]) << '\n';
}

bool Med;
signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	#ifdef FILE
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	int T = 1;
	// cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3904kb

input:

4 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

4 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

4 2
1 2
1 3

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

4 2
1 2
3 4

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

4 3
1 2
1 3
1 4

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

4 3
1 2
2 3
3 4

output:

0

result:

ok 1 number(s): "0"

Test #8:

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

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: 8028kb

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: 7856kb

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: 1ms
memory: 8064kb

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: 8072kb

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: 1ms
memory: 3820kb

input:

633 0

output:

6626427570

result:

ok 1 number(s): "6626427570"

Test #14:

score: -100
Wrong Answer
time: 2ms
memory: 8100kb

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 13 0 0
6606576764

result:

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