#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 1e5 + 5;
vector<vector<int>> vec(maxn);
void input(int n,int m){
while (m--){
int u,v;
cin >> u >> v;
vec[u].push_back(v);
vec[v].push_back(u);
}
}
namespace sub1{
bool check(int n,int m){
return (n <= 10 && m <= 100);
}
const int N = 15;
bool E[N][N],path[N][N][N];
void gen_edge(int n){
for (int u = 1 ; u <= n ; u++)
for (int v : vec[u])
E[u][v] = E[v][u] = 1;
}
void checker(int mask,int n){
vector <int> node;
for (int u = 1 ; u <= n ; u++)
if (1 << (u - 1) & mask)
node.push_back(u);
do{
bool kt = 1;
for (int i = 1 ; i < node.size() ; i++)
if (!E[node[i]][node[i - 1]]){
kt = 0;
break;
}
if (kt)
for (int u : node)
path[node[0]][u][node.back()] = 1;
}while (next_permutation(node.begin(),node.end()));
}
void solve(int n,int m){
gen_edge(n);
int lim_mask = (1 << n);
for (int mask = 1 ; mask < lim_mask ; mask++)
if (__builtin_popcount(mask) >= 3)
checker(mask,n);
int res = 0;
for (int u = 1 ; u <= n ; u++)
for (int v = 1 ; v <= n ; v++)
for (int k = 1 ; k <= n ; k++)
if (u != v && v != k && u != k)
res += path[u][v][k];
cout << res;
}
}
ll res = 0;
int sz[maxn];
ll dfs(int u,int par,int n){
sz[u] = 1;
ll res = 0;
for (int v : vec[u])
if (v != par){
res += dfs(v,u,n);
sz[u] += sz[v];
}
ll cur1 = 0,cur2 = 0;
for (int v : vec[u])
if (v != par){
res += cur2 * (ll)sz[v];
cur2 += cur1 * (ll)sz[v];
cur1 += sz[v];
}
res -= cur2 * (ll)(n - sz[u]);
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
input(n,m);
if (sub1::check(n,m)){
sub1::solve(n,m);
return 0;
}
res = (ll)n*(ll)(n - 1)*(ll)(n - 2)/6;
res -= dfs(1,0,n);
res *= 2;
cout << res;
return 0;
}
Compilation message
count_triplets.cpp: In function 'void sub1::checker(int, int)':
count_triplets.cpp:45:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 1 ; i < node.size() ; i++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 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 |
38 ms |
2652 KB |
Output is correct |
7 |
Correct |
35 ms |
2652 KB |
Output is correct |
8 |
Correct |
45 ms |
2652 KB |
Output is correct |
9 |
Correct |
63 ms |
2648 KB |
Output is correct |
10 |
Correct |
164 ms |
2652 KB |
Output is correct |
11 |
Correct |
36 ms |
2652 KB |
Output is correct |
12 |
Correct |
41 ms |
2652 KB |
Output is correct |
13 |
Correct |
36 ms |
2652 KB |
Output is correct |
14 |
Correct |
36 ms |
2652 KB |
Output is correct |
15 |
Correct |
36 ms |
2652 KB |
Output is correct |
16 |
Correct |
35 ms |
2652 KB |
Output is correct |
17 |
Correct |
35 ms |
2652 KB |
Output is correct |
18 |
Correct |
43 ms |
2652 KB |
Output is correct |
19 |
Correct |
34 ms |
2652 KB |
Output is correct |
20 |
Correct |
34 ms |
2652 KB |
Output is correct |
21 |
Correct |
41 ms |
2652 KB |
Output is correct |
22 |
Correct |
36 ms |
2648 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
5 ms |
2652 KB |
Output is correct |
26 |
Correct |
36 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
5 ms |
2652 KB |
Output is correct |
29 |
Correct |
35 ms |
2664 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
5 ms |
2652 KB |
Output is correct |
32 |
Correct |
36 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2664 KB |
Output is correct |
35 |
Correct |
35 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 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 |
38 ms |
2652 KB |
Output is correct |
7 |
Correct |
35 ms |
2652 KB |
Output is correct |
8 |
Correct |
45 ms |
2652 KB |
Output is correct |
9 |
Correct |
63 ms |
2648 KB |
Output is correct |
10 |
Correct |
164 ms |
2652 KB |
Output is correct |
11 |
Correct |
36 ms |
2652 KB |
Output is correct |
12 |
Correct |
41 ms |
2652 KB |
Output is correct |
13 |
Correct |
36 ms |
2652 KB |
Output is correct |
14 |
Correct |
36 ms |
2652 KB |
Output is correct |
15 |
Correct |
36 ms |
2652 KB |
Output is correct |
16 |
Correct |
35 ms |
2652 KB |
Output is correct |
17 |
Correct |
35 ms |
2652 KB |
Output is correct |
18 |
Correct |
43 ms |
2652 KB |
Output is correct |
19 |
Correct |
34 ms |
2652 KB |
Output is correct |
20 |
Correct |
34 ms |
2652 KB |
Output is correct |
21 |
Correct |
41 ms |
2652 KB |
Output is correct |
22 |
Correct |
36 ms |
2648 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
5 ms |
2652 KB |
Output is correct |
26 |
Correct |
36 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
5 ms |
2652 KB |
Output is correct |
29 |
Correct |
35 ms |
2664 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
5 ms |
2652 KB |
Output is correct |
32 |
Correct |
36 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2664 KB |
Output is correct |
35 |
Correct |
35 ms |
2652 KB |
Output is correct |
36 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
981 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
7456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
7660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 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 |
38 ms |
2652 KB |
Output is correct |
7 |
Correct |
35 ms |
2652 KB |
Output is correct |
8 |
Correct |
45 ms |
2652 KB |
Output is correct |
9 |
Correct |
63 ms |
2648 KB |
Output is correct |
10 |
Correct |
164 ms |
2652 KB |
Output is correct |
11 |
Correct |
36 ms |
2652 KB |
Output is correct |
12 |
Correct |
41 ms |
2652 KB |
Output is correct |
13 |
Correct |
36 ms |
2652 KB |
Output is correct |
14 |
Correct |
36 ms |
2652 KB |
Output is correct |
15 |
Correct |
36 ms |
2652 KB |
Output is correct |
16 |
Correct |
35 ms |
2652 KB |
Output is correct |
17 |
Correct |
35 ms |
2652 KB |
Output is correct |
18 |
Correct |
43 ms |
2652 KB |
Output is correct |
19 |
Correct |
34 ms |
2652 KB |
Output is correct |
20 |
Correct |
34 ms |
2652 KB |
Output is correct |
21 |
Correct |
41 ms |
2652 KB |
Output is correct |
22 |
Correct |
36 ms |
2648 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
5 ms |
2652 KB |
Output is correct |
26 |
Correct |
36 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
5 ms |
2652 KB |
Output is correct |
29 |
Correct |
35 ms |
2664 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
5 ms |
2652 KB |
Output is correct |
32 |
Correct |
36 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2664 KB |
Output is correct |
35 |
Correct |
35 ms |
2652 KB |
Output is correct |
36 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 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 |
38 ms |
2652 KB |
Output is correct |
7 |
Correct |
35 ms |
2652 KB |
Output is correct |
8 |
Correct |
45 ms |
2652 KB |
Output is correct |
9 |
Correct |
63 ms |
2648 KB |
Output is correct |
10 |
Correct |
164 ms |
2652 KB |
Output is correct |
11 |
Correct |
36 ms |
2652 KB |
Output is correct |
12 |
Correct |
41 ms |
2652 KB |
Output is correct |
13 |
Correct |
36 ms |
2652 KB |
Output is correct |
14 |
Correct |
36 ms |
2652 KB |
Output is correct |
15 |
Correct |
36 ms |
2652 KB |
Output is correct |
16 |
Correct |
35 ms |
2652 KB |
Output is correct |
17 |
Correct |
35 ms |
2652 KB |
Output is correct |
18 |
Correct |
43 ms |
2652 KB |
Output is correct |
19 |
Correct |
34 ms |
2652 KB |
Output is correct |
20 |
Correct |
34 ms |
2652 KB |
Output is correct |
21 |
Correct |
41 ms |
2652 KB |
Output is correct |
22 |
Correct |
36 ms |
2648 KB |
Output is correct |
23 |
Correct |
5 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
5 ms |
2652 KB |
Output is correct |
26 |
Correct |
36 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
5 ms |
2652 KB |
Output is correct |
29 |
Correct |
35 ms |
2664 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
5 ms |
2652 KB |
Output is correct |
32 |
Correct |
36 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2652 KB |
Output is correct |
34 |
Correct |
5 ms |
2664 KB |
Output is correct |
35 |
Correct |
35 ms |
2652 KB |
Output is correct |
36 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |