#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3e5+7;
ll n,m,k;
vector<int>g[N];
bool used[N];
bool cu[N];
bool is_cycle(int v, int par){
if(used[v])return true;
used[v]=true;
for(int to:g[v]){
if(to!=par){
if(is_cycle(to, v))return true;
}
}
return false;
}
int length(int v){
cu[v]=true;
int cnt=1;
for(int to:g[v]){
if(!cu[to]){
cnt+=length(to);
}
}
return cnt;
}
int main() {
cin>>n>>m;
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
ll ans=0;
for(int v=0;v<n;v++){
if(!used[v]){
ll cnt=length(v);
if(is_cycle(v, v)){
ans+=cnt*(cnt-1)*(cnt-2);
}
else{
ans+=cnt*(cnt-1)*(cnt-2)/3;
}
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7304 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Incorrect |
3 ms |
7252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7304 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Incorrect |
3 ms |
7252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
15300 KB |
Output is correct |
2 |
Correct |
105 ms |
15360 KB |
Output is correct |
3 |
Correct |
90 ms |
13000 KB |
Output is correct |
4 |
Correct |
69 ms |
14076 KB |
Output is correct |
5 |
Correct |
78 ms |
12200 KB |
Output is correct |
6 |
Correct |
65 ms |
12216 KB |
Output is correct |
7 |
Correct |
65 ms |
11520 KB |
Output is correct |
8 |
Correct |
65 ms |
11864 KB |
Output is correct |
9 |
Correct |
65 ms |
11016 KB |
Output is correct |
10 |
Correct |
79 ms |
11436 KB |
Output is correct |
11 |
Correct |
54 ms |
10572 KB |
Output is correct |
12 |
Correct |
52 ms |
10416 KB |
Output is correct |
13 |
Correct |
48 ms |
10428 KB |
Output is correct |
14 |
Correct |
51 ms |
10328 KB |
Output is correct |
15 |
Correct |
36 ms |
10096 KB |
Output is correct |
16 |
Correct |
37 ms |
9932 KB |
Output is correct |
17 |
Correct |
4 ms |
7508 KB |
Output is correct |
18 |
Correct |
4 ms |
7508 KB |
Output is correct |
19 |
Correct |
4 ms |
7508 KB |
Output is correct |
20 |
Correct |
4 ms |
7508 KB |
Output is correct |
21 |
Correct |
4 ms |
7508 KB |
Output is correct |
22 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
10772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
7316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
10748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7304 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Incorrect |
3 ms |
7252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7304 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Incorrect |
3 ms |
7252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |