#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mem(a,b) memset(a, b, sizeof(a))
#define F first
#define S second
#define Si size
#define pb(x) push_back(x)
typedef double D;
typedef long long ll;
typedef long double ld;
const int MOD=(int)1e9+7,MAX=(int)1e5+10;
int n,m,vis[MAX],dp[MAX];
vector <int> v[MAX];
bool cyc=0;
int dfs(int i,int com) {
if (vis[i]) {cyc=1; return 0;}
vis[i]=1;
int ret=1;
for (auto it:v[i]) {
if (it==com) continue;
ret+=dfs(it,i);
}
return ret;
}
int fac(int n) {
if (dp[n]!=-1) return dp[n];
if (n<=2) return dp[n]=2;
return dp[n]=fac(n-1)*n;
}
int main()
{
mem(dp,-1);
cin>>n>>m;
for (int i=0;i<m;i++) {
int u,x;
cin>>u>>x;
v[u].push_back(x);
v[x].push_back(u);
}
ll ans=0;
for (int i=1;i<=n;i++) {
if (vis[i]) continue;
cyc=0;
int l=dfs(i,-1);
if (l<3) ;
else if (cyc) {
ans+=fac(l);
}
else {
ans+=((l*(l-1)*(l-2))/fac(3))*2;
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
131 ms |
11252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
97 ms |
6776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
6728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |