#include <bits/stdc++.h>
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(998244353)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <int> g[N];
bool mk[N], mkr[N];
int ans, i, j, n, m;
ll anser, siz[N], kol;
void calc(int v, int p)
{
if (p != -1) {siz[p] -= siz[v]; siz[v] += siz[p];}
for (auto it : g[v]) anser += (siz[v] - 1 - siz[it]) * siz[it];
for (auto it : g[v]) {if (p == it) continue; calc(it, v);}
if (p != -1) {siz[v] -= siz[p]; siz[p] += siz[v];}
}
void dfs(int v, int p)
{
siz[v] = 0;
for (auto it : g[v])
{
if (it == p) continue;
dfs(it, v);
siz[v] += siz[it];
}
siz[v]++;
if (i == v) calc(v, -1);
}
bool dostig(int v, int to)
{
if (mk[v]) return 0;
if (v == to) return 1;
mk[v] = 1;
bool f = 0;
for (auto it : g[v]) f |= dostig(it, to);
mk[v] = 0;
if (f && v != i && !mkr[v]) {mkr[v] = 1; ans++;}
return f;
}
bool opr(int v, int p)
{
if (v == i && p != -1) return 1;
mkr[v] = 1;
kol++;
for (auto it : g[v])
{
if (it == p) continue;
if (opr(it, v)) return 1;
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
if (n <= 10 && m <= 100)
{
ans = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j){for (int u = 0; u < 51; u++) mkr[u] = 0; dostig(i, j);}
cout << ans << endl;
exit(0);
}
for (i = 1; i <= n; i++)
{
if (mkr[i]) continue;
kol = 0;
if (opr(i, -1)) anser += max(0ll, kol * (kol - 1) * (kol - 2)); else if (kol > 2) dfs(i, -1);
}
cout << anser << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
7 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
525 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2816 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Correct |
6 ms |
2688 KB |
Output is correct |
29 |
Correct |
6 ms |
2688 KB |
Output is correct |
30 |
Correct |
6 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2688 KB |
Output is correct |
32 |
Correct |
6 ms |
2688 KB |
Output is correct |
33 |
Correct |
6 ms |
2688 KB |
Output is correct |
34 |
Correct |
6 ms |
2688 KB |
Output is correct |
35 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
7 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
525 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2816 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Correct |
6 ms |
2688 KB |
Output is correct |
29 |
Correct |
6 ms |
2688 KB |
Output is correct |
30 |
Correct |
6 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2688 KB |
Output is correct |
32 |
Correct |
6 ms |
2688 KB |
Output is correct |
33 |
Correct |
6 ms |
2688 KB |
Output is correct |
34 |
Correct |
6 ms |
2688 KB |
Output is correct |
35 |
Correct |
6 ms |
2688 KB |
Output is correct |
36 |
Correct |
6 ms |
2688 KB |
Output is correct |
37 |
Correct |
6 ms |
2688 KB |
Output is correct |
38 |
Runtime error |
618 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
10620 KB |
Output is correct |
2 |
Correct |
63 ms |
10620 KB |
Output is correct |
3 |
Correct |
68 ms |
9208 KB |
Output is correct |
4 |
Correct |
89 ms |
11384 KB |
Output is correct |
5 |
Correct |
67 ms |
9592 KB |
Output is correct |
6 |
Correct |
72 ms |
10104 KB |
Output is correct |
7 |
Correct |
72 ms |
9208 KB |
Output is correct |
8 |
Correct |
70 ms |
9336 KB |
Output is correct |
9 |
Correct |
80 ms |
8568 KB |
Output is correct |
10 |
Correct |
70 ms |
8880 KB |
Output is correct |
11 |
Correct |
53 ms |
7676 KB |
Output is correct |
12 |
Correct |
53 ms |
7672 KB |
Output is correct |
13 |
Correct |
45 ms |
7544 KB |
Output is correct |
14 |
Correct |
44 ms |
7416 KB |
Output is correct |
15 |
Correct |
33 ms |
6784 KB |
Output is correct |
16 |
Correct |
34 ms |
6776 KB |
Output is correct |
17 |
Correct |
6 ms |
2816 KB |
Output is correct |
18 |
Correct |
6 ms |
2816 KB |
Output is correct |
19 |
Correct |
7 ms |
2816 KB |
Output is correct |
20 |
Correct |
7 ms |
2816 KB |
Output is correct |
21 |
Correct |
6 ms |
2816 KB |
Output is correct |
22 |
Correct |
6 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
7 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
6776 KB |
Output is correct |
2 |
Correct |
65 ms |
6776 KB |
Output is correct |
3 |
Correct |
63 ms |
6776 KB |
Output is correct |
4 |
Correct |
62 ms |
6776 KB |
Output is correct |
5 |
Correct |
63 ms |
6776 KB |
Output is correct |
6 |
Correct |
85 ms |
10104 KB |
Output is correct |
7 |
Correct |
79 ms |
8952 KB |
Output is correct |
8 |
Correct |
88 ms |
8440 KB |
Output is correct |
9 |
Correct |
86 ms |
7800 KB |
Output is correct |
10 |
Correct |
70 ms |
6776 KB |
Output is correct |
11 |
Correct |
64 ms |
6776 KB |
Output is correct |
12 |
Correct |
61 ms |
6776 KB |
Output is correct |
13 |
Correct |
63 ms |
6776 KB |
Output is correct |
14 |
Correct |
54 ms |
6776 KB |
Output is correct |
15 |
Correct |
48 ms |
6520 KB |
Output is correct |
16 |
Correct |
30 ms |
5888 KB |
Output is correct |
17 |
Correct |
42 ms |
7024 KB |
Output is correct |
18 |
Correct |
42 ms |
7152 KB |
Output is correct |
19 |
Correct |
42 ms |
7156 KB |
Output is correct |
20 |
Correct |
43 ms |
7160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Runtime error |
596 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
6776 KB |
Output is correct |
2 |
Correct |
69 ms |
6808 KB |
Output is correct |
3 |
Runtime error |
630 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
7 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
525 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2816 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Correct |
6 ms |
2688 KB |
Output is correct |
29 |
Correct |
6 ms |
2688 KB |
Output is correct |
30 |
Correct |
6 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2688 KB |
Output is correct |
32 |
Correct |
6 ms |
2688 KB |
Output is correct |
33 |
Correct |
6 ms |
2688 KB |
Output is correct |
34 |
Correct |
6 ms |
2688 KB |
Output is correct |
35 |
Correct |
6 ms |
2688 KB |
Output is correct |
36 |
Correct |
6 ms |
2688 KB |
Output is correct |
37 |
Correct |
6 ms |
2688 KB |
Output is correct |
38 |
Runtime error |
618 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
7 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
525 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2816 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Correct |
6 ms |
2688 KB |
Output is correct |
29 |
Correct |
6 ms |
2688 KB |
Output is correct |
30 |
Correct |
6 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2688 KB |
Output is correct |
32 |
Correct |
6 ms |
2688 KB |
Output is correct |
33 |
Correct |
6 ms |
2688 KB |
Output is correct |
34 |
Correct |
6 ms |
2688 KB |
Output is correct |
35 |
Correct |
6 ms |
2688 KB |
Output is correct |
36 |
Correct |
6 ms |
2688 KB |
Output is correct |
37 |
Correct |
6 ms |
2688 KB |
Output is correct |
38 |
Runtime error |
618 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |