QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#318249#8148. Middle Point GraphPetroTarnavskyiAC ✓2020ms37224kbC++201.9kb2024-01-30 20:10:422024-01-30 20:10:43

Judging History

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

  • [2024-01-30 20:10:43]
  • 评测
  • 测评结果:AC
  • 用时:2020ms
  • 内存:37224kb
  • [2024-01-30 20:10:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int mod = 1e9 + 7;

LL triangles(int n, vector<PII> edges)
{
	vector<VI> g(n);
	int m = SZ(edges);
	VI deg(n, 0);
	FOR (i, 0, m)
	{
		auto [u, v] = edges[i];
		deg[u]++;
		deg[v]++;
	}
	FOR (i, 0, m)
	{
		auto [u, v] = edges[i];
		if (MP(deg[u], u) < MP(deg[v], v))
			g[u].PB(v);
		else
			g[v].PB(u);
	}
	LL cnt3 = 0;
	VI used(n, 0);
	FOR (v, 0, n)
	{
		for (auto u : g[v])
			used[u] = 1;
		for (auto u : g[v])
		{
			for (auto w : g[u])
				if (used[w])
					cnt3++;
		}
		for (auto u : g[v])
			used[u] = 0;
	}
	return cnt3;
}

const int N = 300'000;
VI g[N];

LL rect(int n)
{
	LL cnt4 = 0;
	vector<PII> d(n);
	FOR (v, 0, n) d[v] = MP(SZ(g[v]), v);
	VI L(n);
	FOR (v, 0, n)
	{
		for (auto u : g[v])
			if (d[u] < d[v])
				for (auto y : g[u])
					if (d[y] < d[v])
						cnt4 += L[y], L[y]++;
		for (auto u : g[v])
			if (d[u] < d[v])
				for (auto y : g[u])
					L[y] = 0;
	}
	return cnt4;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<PII> e(m);
	VI d(n);
	FOR (i, 0, m)
	{
		cin >> e[i].F >> e[i].S;
		e[i].F--;
		e[i].S--;
		g[e[i].F].PB(e[i].S);
		g[e[i].S].PB(e[i].F);
		d[e[i].F]++;
		d[e[i].S]++;
	}
	LL c3 = triangles(n, e);
	LL c4 = rect(n);
	LL ans = LL(m) * (n + m - 3);
	
	
	FOR (i, 0, n)
		ans += d[i] * LL(d[i] - 1) / 2;
	cout << (ans + c3 * 3 + c4) % mod << '\n';
	
	FOR (i, 0, n)
		g[i].clear();
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}


这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

3

7 18
2 1
2 3
3 4
2 5
6 4
7 5
6 5
3 1
1 5
1 7
7 3
2 6
2 7
4 5
5 3
4 2
6 7
6 3

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

1 0

output:

593
88
0

result:

ok 3 number(s): "593 88 0"

Test #2:

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

input:

10

2 1
2 1

1 0

3 3
2 1
1 3
3 2

2 1
2 1

2 1
2 1

1 0

2 1
2 1

2 1
1 2

1 0

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

output:

0
0
15
0
0
0
0
0
0
69

result:

ok 10 numbers

Test #3:

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

input:

10

1 0

1 0

2 1
2 1

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

3 3
1 2
3 1
3 2

9 8
1 2
2 3
2 4
2 5
5 6
4 7
8 3
6 9

1 0

3 3
1 2
2 3
3 1

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

1 0

output:

0
0
0
64
15
122
0
15
69
0

result:

ok 10 numbers

Test #4:

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

input:

1

50 50
2 1
2 3
4 1
1 5
1 6
1 7
2 8
9 2
10 5
2 11
7 12
12 13
2 14
10 15
16 2
12 17
18 3
18 19
20 16
1 21
12 22
23 18
24 16
25 5
8 26
27 10
28 12
21 29
30 27
27 31
32 13
33 32
14 34
35 18
33 36
37 30
38 16
17 39
23 40
8 41
35 42
5 43
32 44
32 45
46 39
47 3
48 11
49 18
39 50
5 45

output:

4954

result:

ok 1 number(s): "4954"

Test #5:

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

input:

1

30 50
2 1
2 3
3 4
5 4
2 6
7 5
4 8
3 9
9 10
8 11
4 12
13 6
14 8
15 12
16 10
5 17
2 18
19 16
6 20
8 21
22 21
7 23
15 24
16 25
13 26
20 27
16 28
29 19
15 30
18 10
17 7
16 13
18 19
15 20
18 28
28 15
21 28
21 3
12 23
4 16
27 26
19 9
2 28
10 7
25 9
5 22
15 22
4 27
10 24
16 12

output:

4025

result:

ok 1 number(s): "4025"

Test #6:

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

input:

1

1000 1000
2 1
3 2
2 4
5 2
4 6
6 7
5 8
9 5
1 10
7 11
12 1
4 13
10 14
15 4
16 5
11 17
3 18
9 19
4 20
21 14
22 11
23 9
2 24
25 7
22 26
21 27
28 14
29 23
30 26
31 11
8 32
33 6
10 34
35 33
21 36
37 7
38 1
39 32
40 16
41 28
40 42
43 20
43 44
45 12
14 46
47 3
48 45
49 13
38 50
51 3
52 46
53 49
54 29
55 ...

output:

1999026

result:

ok 1 number(s): "1999026"

Test #7:

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

input:

2

465 465
2 1
2 3
4 2
4 5
6 4
7 2
8 4
9 7
1 10
5 11
12 10
13 7
7 14
15 3
4 16
6 17
18 6
17 19
20 2
5 21
15 22
17 23
24 12
2 25
3 26
11 27
7 28
6 29
29 30
19 31
32 15
11 33
34 33
4 35
8 36
37 16
16 38
15 39
40 8
29 41
42 8
20 43
44 42
45 23
35 46
31 47
45 48
49 11
39 50
51 18
52 39
52 53
26 54
55 49...

output:

431981
571965

result:

ok 2 number(s): "431981 571965"

Test #8:

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

input:

10

38 38
1 2
3 1
4 1
4 5
2 6
7 2
2 8
6 9
4 10
11 1
4 12
11 13
5 14
13 15
7 16
13 17
18 6
19 4
20 11
11 21
18 22
3 23
21 24
12 25
6 26
27 12
28 14
29 14
30 16
31 6
13 32
10 33
34 28
28 35
26 36
15 37
38 4
18 26

34 33
1 2
3 1
3 4
2 5
6 4
6 7
3 8
9 7
4 10
3 11
12 8
5 13
14 10
4 15
12 16
5 17
18 7
19 ...

output:

2848
2167
207687
3185
2551
61432
0
13768
127716
619

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 237ms
memory: 37224kb

input:

1

200000 500000
1 2
1 3
1 4
1 9
10 1
1 15
1 45
1 121
580 1
859 1
47503 1
1 50314
1 60144
62615 1
112616 1
1 141630
1 172171
2 6
2 366
2 534
2 2313
2 3517
2 3690
4649 2
7189 2
2 37784
2 45766
2 53945
5 3
3 8
16 3
3 33
3 148
155 3
3 189
697 3
3746 3
3 5645
3 29590
46100 3
3 132857
3 175635
26 4
29 4
...

output:

1029064

result:

ok 1 number(s): "1029064"

Test #10:

score: 0
Accepted
time: 211ms
memory: 28124kb

input:

2

142566 381939
1 2
8 1
1 10
1 11
1 15
1 42
1 144
1 388
554 1
909 1
15546 1
38439 1
1 79354
1 117244
119416 1
3 2
2 4
2 6
7 2
2 12
18 2
2 366
2 372
1946 2
8509 2
8813 2
2 11657
19598 2
2 34365
3 5
34 3
3 94
103 3
596 3
1778 3
3 1958
3 8965
13289 3
31676 3
36965 3
37538 3
90811 3
3 125297
9 4
21 4
4...

output:

329860510
719239121

result:

ok 2 number(s): "329860510 719239121"

Test #11:

score: 0
Accepted
time: 138ms
memory: 11552kb

input:

10

9129 42610
1 2
1 3
4 1
5 1
18 1
30 1
1 69
1 789
904 1
1 1862
1 4758
7 2
2 10
2 17
2 661
1128 2
2242 2
2 2661
8259 2
8509 2
3 29
79 3
3 86
3 150
3 400
473 3
477 3
3 2225
3 3417
3 5843
4 12
4 14
37 4
4 122
4 153
245 4
255 4
354 4
4 527
1159 4
4 2614
4 3089
4 3854
4399 4
4 5379
4 6117
6413 4
4 7925...

output:

204908516
71692365
172496393
280630811
661096409
1029943
834960655
776344491
64274552
346772110

result:

ok 10 numbers

Test #12:

score: 0
Accepted
time: 129ms
memory: 9448kb

input:

20

2604 11844
1 2
3 1
4 1
108 1
124 1
1 349
1 1277
1 1415
1 1517
1706 1
2365 1
1 2480
5 2
2 6
2 14
2 18
126 2
170 2
2 189
2 280
2 418
578 2
902 2
2 1626
2426 2
60 3
3 76
351 3
3 640
3 1248
7 4
9 4
4 10
4 42
4 110
2251 4
8 5
12 5
17 5
5 183
490 5
637 5
692 5
776 5
5 1284
2087 5
2340 5
2370 5
2455 5
...

output:

171207587
591910409
655247056
10725
230460448
50006952
942410958
801609893
472450535
100115090
590130419
133326603
280253593
11942031
61041524
315965858
19957752
307791784
395041475
10367647

result:

ok 20 numbers

Test #13:

score: 0
Accepted
time: 115ms
memory: 5316kb

input:

100

342 5076
2 1
3 2
3 4
5 3
6 5
2 7
8 5
9 3
2 10
10 11
12 7
1 13
10 14
2 15
13 16
8 17
18 15
8 19
9 20
21 2
9 22
23 3
1 24
25 3
1 26
27 17
15 28
29 19
30 28
31 9
32 4
9 33
34 32
35 9
36 35
32 37
38 31
12 39
24 40
41 19
28 42
43 5
44 24
12 45
24 46
42 47
48 6
39 49
6 50
51 12
52 51
53 44
42 54
55 4...

output:

27746759
50658517
10683786
24139720
25932859
47565852
350610
11486775
1319626
12904287
14148993
47015672
135120800
161318098
467490
12777493
6450863
62320822
20009150
334697950
195220423
56701910
29206042
7394506
1413245
19254945
20145190
14605944
4172671
494307456
4613126
4221870
1420419
29162821
7...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 103ms
memory: 4644kb

input:

200

3492 4712
1 2
3 1
6 1
1 8
23 1
28 1
35 1
89 1
1 153
343 1
487 1
1 611
1852 1
2 5
7 2
2 27
33 2
2 39
132 2
2 217
2 364
2 866
2 1154
2914 2
3 4
9 3
3 16
3 471
546 3
1777 3
3 1987
2540 3
12 4
17 4
4 22
45 4
4 50
70 4
495 4
4 524
13 5
5 21
641 5
5 2283
3156 5
11 6
15 6
6 20
6 138
6 543
7 162
7 399
...

output:

38655363
1017898
3567787
1321355
19004105
42329957
28643577
21376173
18547078
10433752
39780
33142803
621975
4919571
9899302
1993502
4281270
9585129
5774276
722395
29367261
6297777
7238668
1097217
10514340
6239585
814133
21693865
60622602
20043975
3728795
3690
328471
9289139
2691351
13402
21489221
4...

result:

ok 200 numbers

Test #15:

score: 0
Accepted
time: 103ms
memory: 3956kb

input:

1000

242 624
2 1
1 3
1 4
4 5
4 6
1 7
2 8
9 7
10 4
11 9
12 6
10 13
9 14
11 15
16 1
8 17
3 18
19 5
20 12
3 21
22 15
23 22
1 24
25 22
26 14
27 17
22 28
29 10
3 30
31 30
22 32
33 22
34 3
23 35
8 36
34 37
38 6
39 6
36 40
41 24
42 13
38 43
38 44
45 31
3 46
7 47
48 26
44 49
50 6
51 8
12 52
4 53
23 54
13 5...

output:

541912
509357
55819
187902
98340
156244
366366
10725
693
2130479
69305
1662331
306918
49195
243743
519758
54684
267804
0
154013
9860
625485
55900
7755
350818
764595
1250337
13067
440600
2394
271649
326377
32180
568235
43508
123292
225968
12422
340577
497708
1955209
10439
116167
88379
31620
89884
178...

result:

ok 1000 numbers

Test #16:

score: 0
Accepted
time: 91ms
memory: 3928kb

input:

2000

12 66
1 2
1 3
4 1
5 1
6 1
5 7
7 8
9 8
3 10
11 9
12 6
7 12
4 9
2 10
11 8
1 9
2 11
8 2
4 3
11 10
2 7
2 9
3 7
5 10
8 5
12 8
9 6
1 11
10 8
11 7
6 4
6 5
10 7
4 2
4 7
11 12
9 10
7 6
9 12
6 10
11 3
12 10
4 5
11 5
12 4
2 12
5 9
12 3
8 3
2 6
7 1
6 8
1 12
7 9
8 4
6 11
8 1
3 5
3 6
3 9
11 4
3 2
1 10
10 4
...

output:

7755
448
12168
767060
24305
106260
378278
102105
18092
231493
49525
19072
251
7153
39571
13041
261908
4913
712783
7065
58838
404651
32739
2394
0
169212
18999
87040
32950
61917
288935
3274
86607
12016
1255
22553
131906
37114
127868
5604
70109
117728
24780
334135
55381
512084
47103
58577
42172
5634
14...

result:

ok 2000 numbers

Test #17:

score: 0
Accepted
time: 85ms
memory: 3764kb

input:

10000

16 45
1 2
1 3
2 4
2 5
3 6
7 5
8 6
6 9
10 8
3 11
7 12
4 13
14 2
15 1
16 8
14 16
12 3
5 6
4 16
11 15
13 14
13 7
4 5
6 7
9 10
6 10
10 4
16 10
3 13
11 16
5 15
3 8
16 12
1 14
2 15
13 12
15 6
9 1
1 10
2 12
7 4
9 2
16 2
10 5
11 14

11 55
1 2
2 3
4 3
5 1
5 6
7 3
8 4
1 9
5 10
9 11
11 1
2 7
2 6
7 11
5 ...

output:

2972
5445
4206
69
19052
1899
23656
1040
11373
6179
15
41337
840
840
69
2394
2806
724
0
2126
15
876
1269
1281
10790
297
1300
1026
10098
0
6438
840
195
69
2146
0
2325
3782
6490
840
840
19124
270
1760
22373
995
1466
435
1470
113
5039
777
3461
9593
8651
457
4143
5265
10725
396
4716
45
1836
3598
435
1470...

result:

ok 10000 numbers

Test #18:

score: 0
Accepted
time: 2020ms
memory: 18268kb

input:

1

1000 499500
52 697
781 742
301 407
36 931
460 749
986 912
376 404
463 618
80 297
974 429
829 470
826 952
3 455
207 396
917 627
280 272
769 209
938 37
753 174
411 134
904 115
207 567
297 807
273 627
658 859
556 696
729 813
886 813
692 998
43 614
468 441
326 702
287 162
930 1000
905 629
526 206
86 ...

output:

246625125

result:

ok 1 number(s): "246625125"

Test #19:

score: 0
Accepted
time: 520ms
memory: 30524kb

input:

1

100000 500000
2209 34206
1944 19358
23598 51829
63541 70843
21139 96565
13029 43066
22246 49561
92241 98233
92260 23681
27750 49786
88490 87218
89973 52483
82685 90036
38099 65470
8067 31922
31802 30874
42728 77117
91975 1928
92346 73802
72378 20638
69198 39151
14265 74104
4697 2506
5196 99602
23...

output:

742969024

result:

ok 1 number(s): "742969024"

Test #20:

score: 0
Accepted
time: 728ms
memory: 29176kb

input:

1

100000 500000
43432 62093
91287 71798
90007 35557
47284 48843
97621 23840
29292 16347
34888 85828
5613 86342
43335 13417
86876 33408
36224 71870
54350 43055
38323 45413
2381 23696
65973 84499
57177 29683
10414 21937
4612 50234
87387 26141
66133 84702
57804 57706
93606 61130
57255 61915
7686 87550...

output:

935092768

result:

ok 1 number(s): "935092768"

Test #21:

score: 0
Accepted
time: 1041ms
memory: 30660kb

input:

1

100000 500000
44547 48301
9608 16597
22027 78003
27167 62437
12347 59691
89469 56645
81810 11546
21396 74363
48211 95880
46264 8881
25830 42304
18402 62262
18805 54355
84208 66811
74672 78293
54114 81750
86249 86111
25215 85890
53113 75947
49294 56350
88057 19643
59805 58826
92298 61875
56382 822...

output:

220868041

result:

ok 1 number(s): "220868041"

Test #22:

score: 0
Accepted
time: 1304ms
memory: 29188kb

input:

1

100000 500000
96791 13976
44118 17547
78496 30994
97506 88040
8906 51005
77021 74888
97902 48162
17229 18353
51325 97122
3306 59388
7577 10449
47744 11670
84887 34741
19536 31938
81636 81995
17614 5844
24509 37955
86244 12119
96693 82879
50606 40809
70451 60920
39773 58394
84881 44377
80084 69361...

output:

925493025

result:

ok 1 number(s): "925493025"

Test #23:

score: 0
Accepted
time: 1395ms
memory: 29200kb

input:

1

100000 500000
35359 1034
11810 16108
83818 78042
41121 13251
34512 90055
54673 50443
51144 31693
40115 85912
47296 53145
22814 75633
64983 66572
53790 38513
31620 63451
32431 46633
53421 77554
7078 73115
75089 42732
33769 87616
17695 41885
48626 51844
22908 65001
94607 3429
24354 30538
39205 4331...

output:

839187312

result:

ok 1 number(s): "839187312"

Test #24:

score: 0
Accepted
time: 1550ms
memory: 28544kb

input:

1

100000 500000
5955 90429
40833 94860
48709 86793
19112 98398
30713 70527
58292 7578
76051 3635
5893 14991
96157 53776
493 78081
94963 66483
52562 85192
48453 4334
69584 76783
62968 25510
46645 19189
65189 88310
42884 4751
63801 66282
32178 93828
96244 48805
22796 63248
42314 88251
9775 73058
7264...

output:

143933648

result:

ok 1 number(s): "143933648"

Test #25:

score: 0
Accepted
time: 1284ms
memory: 28328kb

input:

1

100000 500000
57678 58079
18086 82083
74301 18654
49578 57999
63623 12201
15376 82690
54698 50641
40422 48978
83654 25805
34688 24278
95489 20118
52725 7435
37 81356
90624 51727
93309 69647
82272 41961
81755 8038
95800 26175
94965 21244
99311 97117
73955 53726
55634 26645
11715 10526
99693 31226
...

output:

725291929

result:

ok 1 number(s): "725291929"

Test #26:

score: 0
Accepted
time: 1175ms
memory: 28308kb

input:

1

100000 500000
21374 19010
41479 86322
75621 70857
27899 51043
47155 49678
62463 72682
20160 87284
11979 832
98088 63461
3485 31006
18604 57934
56153 97956
52048 70496
1028 39158
16731 38929
79976 79098
18137 60537
60724 60571
91996 50261
65913 34089
47735 75976
72462 18871
94946 98869
60620 69340...

output:

505321930

result:

ok 1 number(s): "505321930"

Test #27:

score: 0
Accepted
time: 1104ms
memory: 28208kb

input:

1

100000 500000
29154 2904
15325 10735
50873 49136
72195 38289
22498 13916
95488 4953
22121 84204
54737 32603
57308 86164
89913 31597
54638 73196
85595 88712
69432 81296
58049 46603
89940 7488
80856 83640
91809 16514
46257 9845
20226 98011
8130 70925
9726 32954
6595 69837
70401 77134
45938 82311
72...

output:

809243221

result:

ok 1 number(s): "809243221"

Extra Test:

score: 0
Extra Test Passed