QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318226 | #8148. Middle Point Graph | PetroTarnavskyi | WA | 619ms | 27584kb | C++20 | 2.2kb | 2024-01-30 19:16:21 | 2024-01-30 19:16:22 |
Judging History
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;
}
LL rect(int n, vector<PII> edges)
{
vector<VI> g(n);
int m = SZ(edges);
FOR (i, 0, m)
{
auto [u, v] = edges[i];
g[u].PB(v);
g[v].PB(u);
}
FOR (i, 0, n)
{
sort(ALL(g[i]), [&](int u, int v)
{
return MP(SZ(g[u]), u) < MP(SZ(g[v]), v);
});
}
int cnt4 = 0;
vector<LL> L(n);
FOR (v, 0, n)
{
for (auto u : g[v])
{
if (MP(SZ(g[u]), u) > MP(SZ(g[v]), v))
break;
for (auto y : g[u])
{
if (MP(SZ(g[y]), y) >= MP(SZ(g[v]), v))
break;
cnt4 += L[y];
L[y]++;
}
}
for (auto u : g[v])
{
if (MP(SZ(g[u]), u) > MP(SZ(g[v]), v))
break;
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--;
d[e[i].F]++;
d[e[i].S]++;
}
LL c3 = triangles(n, e);
LL c4 = rect(n, e);
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';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3496kb
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: 0ms
memory: 3492kb
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: 0ms
memory: 3492kb
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: 0ms
memory: 3624kb
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: 0ms
memory: 3828kb
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: 0ms
memory: 3892kb
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: 3584kb
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: 3808kb
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: 174ms
memory: 27584kb
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: 173ms
memory: 21420kb
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: 146ms
memory: 7824kb
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: 131ms
memory: 7228kb
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: 126ms
memory: 4688kb
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: 124ms
memory: 4008kb
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: 123ms
memory: 4020kb
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: 113ms
memory: 3772kb
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: 102ms
memory: 3724kb
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: -100
Wrong Answer
time: 619ms
memory: 15480kb
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:
692574416
result:
wrong answer 1st numbers differ - expected: '246625125', found: '692574416'