QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318221 | #8148. Middle Point Graph | PetroTarnavskyi | WA | 207ms | 27592kb | C++20 | 2.1kb | 2024-01-30 19:11:26 | 2024-01-30 19:11:26 |
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;
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);
}
int 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);
});
}
LL 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]++;
}
int c3 = triangles(n, e);
LL c4 = rect(n, e);
int ans = LL(m) * (n + m - 3);
FOR (i, 0, n)
ans += d[i] * LL(d[i] - 1) / 2;
cout << ans + c3 * 3 + c4 << '\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: 1ms
memory: 3620kb
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: 3496kb
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: 3620kb
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: 3596kb
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: 3560kb
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: 3832kb
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: 3608kb
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: 3660kb
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: -100
Wrong Answer
time: 207ms
memory: 27592kb
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:
2108680538
result:
wrong answer 1st numbers differ - expected: '1029064', found: '2108680538'