#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)
using namespace std;
ll fp(ll x , ll y)
{
if(y==0)
return 1;
ll z = fp(x,y/2);
if(y&1)
return z*z*x;
else
return z*z;
}
int sqrot(ll x)
{
int l = 0 , r = INT_MAX;
while(l<=r)
{
if(mid*mid>=x)
r=mid-1;
else
l=mid+1;
}
return r+1;
}
ll cel(ll x , ll y)
{
return x/y + bool(x%y);
}
string tb(ll x)
{
string s = "";
while(x>0)
{
if(x&1)
s+='1';
else
s+='0';
x/=2;
}
while(s.size()<60)
s+='0';
return s;
}
ll fb(string s)
{
ll x = 0;
ll c = 1;
for(int8_t i = 0 ; 60>i ; i++)
{
if(s[i]=='1')
x+=c;
c*=2;
}
return x;
}
ll n , m;
vector<ll> adj[100009];
bool vis[100009];
vector<ll> v;
void dfs(ll i)
{
if(vis[i])
return;
vis[i]=1;
v.pb(i);
for(auto it : adj[i])
dfs(it);
}
int main()
{
cin >> n >> m;
for(int i = 0 ; m>i ; i++)
{
ll u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
ll ans = 0;
for(int i = 1 ; n>=i ; i++)
{
if(vis[i])
continue;
v.clear();
dfs(i);
if(v.size()<=2)
continue;
bool l = 0;
for(auto it : v)
{
if(adj[it].size()==1)
l=1;
}
ll sz = v.size();
ll ans1 = sz*(sz-1)*(sz-2);
if(l)
ans1/=3;
ans+=ans1;
}
cans
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2796 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2796 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2796 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2796 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
12692 KB |
Output is correct |
2 |
Correct |
59 ms |
12752 KB |
Output is correct |
3 |
Correct |
57 ms |
10028 KB |
Output is correct |
4 |
Correct |
60 ms |
11308 KB |
Output is correct |
5 |
Correct |
55 ms |
9432 KB |
Output is correct |
6 |
Correct |
57 ms |
9296 KB |
Output is correct |
7 |
Correct |
96 ms |
8304 KB |
Output is correct |
8 |
Correct |
71 ms |
8928 KB |
Output is correct |
9 |
Correct |
59 ms |
7748 KB |
Output is correct |
10 |
Correct |
58 ms |
8404 KB |
Output is correct |
11 |
Correct |
47 ms |
6996 KB |
Output is correct |
12 |
Correct |
45 ms |
6748 KB |
Output is correct |
13 |
Correct |
44 ms |
6740 KB |
Output is correct |
14 |
Correct |
43 ms |
6440 KB |
Output is correct |
15 |
Correct |
32 ms |
6172 KB |
Output is correct |
16 |
Correct |
32 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
9128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
8908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2796 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2796 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2796 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2796 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |