#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
using namespace std;
constexpr static int MXN = 1e5;
int n, m;
vector<int> g[MXN];
bitset<MXN> visited;
int subtree_size[MXN];
int sum;
bool dfs(int node, int p)
{
visited[node] = true;
sum++;
for (int c : g[node])
{
if (c == p)
continue;
if (visited[c])
return true;
if (dfs(c, node))
return true;
}
return false;
}
int32_t main()
{
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--,b--;
g[a].pb(b);
g[b].pb(a);
}
int res = 0;
for (int i = 0; i < n; i++)
{
if (!visited[i])
{
sum = 0;
bool circular = dfs(i, i);
if (circular)
res += sum * (sum - 1) * (sum - 2);
else
res += sum * (sum - 1) * (sum - 2) / 3;
}
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2660 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2624 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2660 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2624 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
12032 KB |
Output is correct |
2 |
Correct |
70 ms |
12620 KB |
Output is correct |
3 |
Correct |
59 ms |
9544 KB |
Output is correct |
4 |
Correct |
60 ms |
11024 KB |
Output is correct |
5 |
Correct |
63 ms |
8432 KB |
Output is correct |
6 |
Correct |
68 ms |
8392 KB |
Output is correct |
7 |
Correct |
62 ms |
7568 KB |
Output is correct |
8 |
Correct |
57 ms |
8116 KB |
Output is correct |
9 |
Correct |
58 ms |
7024 KB |
Output is correct |
10 |
Correct |
64 ms |
7616 KB |
Output is correct |
11 |
Correct |
64 ms |
6292 KB |
Output is correct |
12 |
Correct |
75 ms |
6224 KB |
Output is correct |
13 |
Correct |
47 ms |
6176 KB |
Output is correct |
14 |
Correct |
44 ms |
6092 KB |
Output is correct |
15 |
Correct |
32 ms |
5748 KB |
Output is correct |
16 |
Correct |
34 ms |
5704 KB |
Output is correct |
17 |
Correct |
2 ms |
2664 KB |
Output is correct |
18 |
Correct |
2 ms |
2656 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
6332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
6396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2660 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2624 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2660 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2624 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |