#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;
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);
}
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 (n <= 10)
sub1(n);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
31 ms |
4188 KB |
Output is correct |
10 |
Execution timed out |
1018 ms |
4312 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
31 ms |
4188 KB |
Output is correct |
10 |
Execution timed out |
1018 ms |
4312 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
10576 KB |
Output is correct |
2 |
Correct |
61 ms |
11964 KB |
Output is correct |
3 |
Correct |
59 ms |
10312 KB |
Output is correct |
4 |
Correct |
60 ms |
11088 KB |
Output is correct |
5 |
Correct |
75 ms |
9772 KB |
Output is correct |
6 |
Correct |
80 ms |
9700 KB |
Output is correct |
7 |
Correct |
105 ms |
9296 KB |
Output is correct |
8 |
Correct |
77 ms |
9736 KB |
Output is correct |
9 |
Correct |
58 ms |
8936 KB |
Output is correct |
10 |
Correct |
63 ms |
9408 KB |
Output is correct |
11 |
Correct |
65 ms |
8528 KB |
Output is correct |
12 |
Correct |
62 ms |
8360 KB |
Output is correct |
13 |
Correct |
46 ms |
8316 KB |
Output is correct |
14 |
Correct |
48 ms |
8064 KB |
Output is correct |
15 |
Correct |
46 ms |
7676 KB |
Output is correct |
16 |
Correct |
37 ms |
7408 KB |
Output is correct |
17 |
Correct |
2 ms |
4440 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4336 KB |
Output is correct |
20 |
Correct |
3 ms |
4444 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
8020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
8020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
31 ms |
4188 KB |
Output is correct |
10 |
Execution timed out |
1018 ms |
4312 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
31 ms |
4188 KB |
Output is correct |
10 |
Execution timed out |
1018 ms |
4312 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |