#include <iostream>
#include <vector>
using namespace std;
#define int long long
const int N = 1e5 + 10;
vector<int> nei[N];
bool seen[55][55][55];
int d[N],Seen[N], cur = 1, ver, ed, ch[N];
void dfs1(int u,vector<int> v){
v.push_back(u);
for (int i : v)
seen[v[0]][u][i] = 1;
for (int i : nei[u]){
bool ns = 1;
for (int j : v)
if (j == i)
ns = false;
if (ns)
dfs1(i,v);
}
}
void sub1(int n){
for (int i=1;i<=n;i++)
dfs1(i,{});
int ans = 0;
for (int s = 1;s <= n; s++)
for (int c = 1;c <= n; c++)
for (int f = 1;f <= n; f++)
if ( !(s == c or s == f or c == f) )
ans += seen[s][f][c];
cout<<ans<<'\n';
exit(0);
}
void dfs2(int u){
Seen[u] = cur;
ver++;
ed += d[u];
for (int i : nei[u])
if (Seen[i] != cur)
dfs2(i);
}
void sub3(int n){
int ans = 0;
for (int i=1;i<=n;i++)
if (Seen[i] != cur){
ver = 0;
ed = 0;
dfs2(i);
ed >>= 1;
if (ed == ver - 1)
for (int j=1;j<=ver;j++)
ans += (j - 1) * (ver - j) * 2;
else
ans += ver * (ver-1) * (ver-2);
}
cout<<ans<<'\n';
exit(0);
}
void dfs31(int u,int p = -1){
Seen[u] = true;
ch[u] = 1;
for (int i : nei[u])
if (i != p)
dfs31(i,u),ch[u] += ch[i];
}
int ans = 0;
void dfs32(int u,int p = -1){
int S = ch[1] - ch[u];
for (int i : nei[u])
if (i != p)
ans += ch[i] * S,S += ch[i];
for (int i : nei[u])
if (i != p)
dfs32(i,u);
}
void sub45(int n){
for (int i=1;i<=n;i++)
if (!Seen[i]){
dfs31(i);
dfs32(i);
}
cout<<ans * 2<<'\n';
exit(0);
}
signed main(){
int n,m;
cin>>n>>m;
int mx = 0;
for (int i=1;i<=m;i++){
int a,b;
cin>>a>>b;
nei[a].push_back(b);
nei[b].push_back(a);
d[a]++;
d[b]++;
mx = max(mx,max(d[a],d[b]));
}
// if (mx <= 2)
// sub3(n);
if (m == n-1)
sub45(n);
// if (n <= 10)
// sub1(n);
}
/*
16 15
1 2
1 3
3 4
3 5
3 6
5 7
5 8
5 9
2 10
2 11
11 12
11 13
13 15
13 16
13 14
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
9300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5124 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Incorrect |
4 ms |
5128 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
10068 KB |
Output is correct |
2 |
Correct |
59 ms |
10068 KB |
Output is correct |
3 |
Correct |
57 ms |
10064 KB |
Output is correct |
4 |
Correct |
58 ms |
10264 KB |
Output is correct |
5 |
Correct |
77 ms |
10020 KB |
Output is correct |
6 |
Correct |
63 ms |
13040 KB |
Output is correct |
7 |
Correct |
65 ms |
12360 KB |
Output is correct |
8 |
Correct |
63 ms |
11768 KB |
Output is correct |
9 |
Correct |
72 ms |
11092 KB |
Output is correct |
10 |
Incorrect |
53 ms |
10072 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
10200 KB |
Output is correct |
2 |
Correct |
63 ms |
10064 KB |
Output is correct |
3 |
Incorrect |
62 ms |
10576 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |