#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[200001];
bool visited[200001];
int DP[200001][4];
bool isCycle;
int tot;
void dfs(int x,int p){
if(visited[x]){
isCycle=true;
return;
}
tot++;
visited[x]=true;
for(int&i:adj[x])if(i!=p)dfs(i,x);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for(auto&i:DP)i[0]=1;
for(int i=1;i<=200000;i++)for(int j=1;j<=3;j++)DP[i][j]=DP[i-1][j]+DP[i-1][j-1];
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
int ans = 0;
for(int i=1;i<=n;i++)if(!visited[i]){
isCycle = false;
tot = 0;
dfs(i,0);
if(isCycle)ans+=tot*(tot-1ll)*(tot-2ll);
else ans+=2ll*DP[tot][3];
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
11356 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
3 ms |
11356 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Incorrect |
3 ms |
11356 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
11356 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
3 ms |
11356 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Incorrect |
3 ms |
11356 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
19292 KB |
Output is correct |
2 |
Correct |
29 ms |
19284 KB |
Output is correct |
3 |
Correct |
29 ms |
16816 KB |
Output is correct |
4 |
Correct |
41 ms |
19284 KB |
Output is correct |
5 |
Correct |
30 ms |
17500 KB |
Output is correct |
6 |
Correct |
36 ms |
17492 KB |
Output is correct |
7 |
Correct |
29 ms |
16716 KB |
Output is correct |
8 |
Correct |
30 ms |
17236 KB |
Output is correct |
9 |
Correct |
29 ms |
16208 KB |
Output is correct |
10 |
Correct |
29 ms |
16720 KB |
Output is correct |
11 |
Correct |
25 ms |
15700 KB |
Output is correct |
12 |
Correct |
26 ms |
15452 KB |
Output is correct |
13 |
Correct |
23 ms |
15452 KB |
Output is correct |
14 |
Correct |
25 ms |
15232 KB |
Output is correct |
15 |
Correct |
18 ms |
14680 KB |
Output is correct |
16 |
Correct |
18 ms |
14688 KB |
Output is correct |
17 |
Correct |
3 ms |
11612 KB |
Output is correct |
18 |
Correct |
3 ms |
11820 KB |
Output is correct |
19 |
Correct |
4 ms |
11612 KB |
Output is correct |
20 |
Correct |
3 ms |
11612 KB |
Output is correct |
21 |
Correct |
3 ms |
11612 KB |
Output is correct |
22 |
Correct |
3 ms |
11612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
11612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
15184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
11608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
15128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
11356 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
3 ms |
11356 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Incorrect |
3 ms |
11356 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
11356 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
3 ms |
11356 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Incorrect |
3 ms |
11356 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |