#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 2e5;
vector<int> g[nax];
int seg[4*nax],lazy[4*nax],fr[nax],to[nax],id[nax];
int T,n,m;
ll ans;
void pro(int n,int s,int e){
seg[n] += lazy[n]*(e-s+1);
if(s != e){
lazy[n*2] += lazy[n];
lazy[n*2+1] += lazy[n];
}
lazy[n] = 0;
}
void update(int n,int s,int e,int l,int r,int val){
pro(n,s,e);
if(s > r || e < l)
return;
if(s >= l && e <= r){
lazy[n] += val;
pro(n,s,e);
return;
}
update(n*2,s,(s+e)/2,l,r,val);
update(n*2+1,(s+e)/2+1,e,l,r,val);
seg[n] = seg[n*2] + seg[n*2+1];
}
void dfs(int u,int p,int d){
id[u] = fr[u] = ++T;
update(1,1,n,T,T,d);
for(int v : g[u]){
if(v == p)
continue;
dfs(v,u,d+1);
}
to[u] = T;
}
void calc(int u,int p){
ans += seg[1] - n + 1;
for(int v : g[u]){
if(v == p)
continue;
update(1,1,n,1,n,1);
update(1,1,n,fr[v],to[v],-2);
calc(v,u);
update(1,1,n,1,n,-1);
update(1,1,n,fr[v],to[v],2);
}
}
const int kax = 100;
bool can[kax],vis[kax];
int count(int u,int t){
if(u == t)return 1;
vis[u] = 1;
for(int v : g[u]){
if(vis[v])continue;
// cout << v << ' ' << u << endl;
can[u] |= count(v,t);
}
vis[u] = 0;
return can[u];
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
if(n <= 10){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j)continue;
memset(can,0,sizeof(can));
// cout << i << ' ' << j << endl;
count(i,j);
// cout << i << ' ' << j << endl;
for(int x=1;x<=n;x++){
if(x == i || x == j)continue;
// if(can[x])cout << i << ' ' << x << ' ' << j << endl;
ans += can[x];
}
}
}
}else if(n == m){
ans = n * 1ll * (n-1) * (n-2);
}else if(n - 1 == m){
dfs(1,0,0);
calc(1,0);
}else assert(0);
printf("%lld\n", ans);
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
22 ms |
4992 KB |
Output is correct |
10 |
Correct |
327 ms |
5060 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4900 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
6 ms |
4992 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
5 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
4992 KB |
Output is correct |
23 |
Correct |
5 ms |
4992 KB |
Output is correct |
24 |
Correct |
5 ms |
4992 KB |
Output is correct |
25 |
Correct |
6 ms |
4992 KB |
Output is correct |
26 |
Correct |
5 ms |
4992 KB |
Output is correct |
27 |
Correct |
5 ms |
4992 KB |
Output is correct |
28 |
Correct |
5 ms |
4992 KB |
Output is correct |
29 |
Correct |
5 ms |
4992 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
4992 KB |
Output is correct |
32 |
Correct |
5 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
4992 KB |
Output is correct |
34 |
Correct |
5 ms |
4992 KB |
Output is correct |
35 |
Correct |
6 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
22 ms |
4992 KB |
Output is correct |
10 |
Correct |
327 ms |
5060 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4900 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
6 ms |
4992 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
5 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
4992 KB |
Output is correct |
23 |
Correct |
5 ms |
4992 KB |
Output is correct |
24 |
Correct |
5 ms |
4992 KB |
Output is correct |
25 |
Correct |
6 ms |
4992 KB |
Output is correct |
26 |
Correct |
5 ms |
4992 KB |
Output is correct |
27 |
Correct |
5 ms |
4992 KB |
Output is correct |
28 |
Correct |
5 ms |
4992 KB |
Output is correct |
29 |
Correct |
5 ms |
4992 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
4992 KB |
Output is correct |
32 |
Correct |
5 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
4992 KB |
Output is correct |
34 |
Correct |
5 ms |
4992 KB |
Output is correct |
35 |
Correct |
6 ms |
4992 KB |
Output is correct |
36 |
Runtime error |
12 ms |
9984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
8188 KB |
Output is correct |
2 |
Correct |
68 ms |
8184 KB |
Output is correct |
3 |
Execution timed out |
1075 ms |
201436 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
7 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Runtime error |
11 ms |
9984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
11588 KB |
Output is correct |
2 |
Correct |
210 ms |
11512 KB |
Output is correct |
3 |
Correct |
219 ms |
11640 KB |
Output is correct |
4 |
Correct |
233 ms |
11512 KB |
Output is correct |
5 |
Correct |
205 ms |
11512 KB |
Output is correct |
6 |
Incorrect |
240 ms |
14840 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Runtime error |
11 ms |
9984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
11644 KB |
Output is correct |
2 |
Correct |
219 ms |
11512 KB |
Output is correct |
3 |
Runtime error |
69 ms |
16248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
22 ms |
4992 KB |
Output is correct |
10 |
Correct |
327 ms |
5060 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4900 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
6 ms |
4992 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
5 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
4992 KB |
Output is correct |
23 |
Correct |
5 ms |
4992 KB |
Output is correct |
24 |
Correct |
5 ms |
4992 KB |
Output is correct |
25 |
Correct |
6 ms |
4992 KB |
Output is correct |
26 |
Correct |
5 ms |
4992 KB |
Output is correct |
27 |
Correct |
5 ms |
4992 KB |
Output is correct |
28 |
Correct |
5 ms |
4992 KB |
Output is correct |
29 |
Correct |
5 ms |
4992 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
4992 KB |
Output is correct |
32 |
Correct |
5 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
4992 KB |
Output is correct |
34 |
Correct |
5 ms |
4992 KB |
Output is correct |
35 |
Correct |
6 ms |
4992 KB |
Output is correct |
36 |
Runtime error |
12 ms |
9984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
22 ms |
4992 KB |
Output is correct |
10 |
Correct |
327 ms |
5060 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4900 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
6 ms |
4992 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
5 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
4992 KB |
Output is correct |
23 |
Correct |
5 ms |
4992 KB |
Output is correct |
24 |
Correct |
5 ms |
4992 KB |
Output is correct |
25 |
Correct |
6 ms |
4992 KB |
Output is correct |
26 |
Correct |
5 ms |
4992 KB |
Output is correct |
27 |
Correct |
5 ms |
4992 KB |
Output is correct |
28 |
Correct |
5 ms |
4992 KB |
Output is correct |
29 |
Correct |
5 ms |
4992 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
4992 KB |
Output is correct |
32 |
Correct |
5 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
4992 KB |
Output is correct |
34 |
Correct |
5 ms |
4992 KB |
Output is correct |
35 |
Correct |
6 ms |
4992 KB |
Output is correct |
36 |
Runtime error |
12 ms |
9984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
37 |
Halted |
0 ms |
0 KB |
- |