Submission #64941

# Submission time Handle Problem Language Result Execution time Memory
64941 2018-08-06T08:09:27 Z gusfring Duathlon (APIO18_duathlon) C++14
49 / 100
59 ms 16392 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define pb push_back
const int N=100005,M=100005;

vector<int> g[N*2];
int hd[N],to[M],ne[M],num,n,m,siz[N*2];
int v[N],cnt,dc,dfn[N],low[N],nn;
ll ans=0;

struct lines{ int x,y;};
stack<lines> S;

inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;}

void tarjan(int x,int fa){
  dfn[x] = low[x] = ++dc, nn++;
  for(int i=hd[x]; i; i=ne[i]) if(to[i]!=fa)
    if(!dfn[to[i]]){
      S.push((lines){x,to[i]});
      tarjan(to[i],x), low[x] = min(low[x], low[to[i]]);
      if(low[to[i]] >= dfn[x]){
        cnt++; lines e;
        for(e=S.top(),S.pop();;e=S.top(),S.pop()){
          if(v[e.x]!=cnt) v[e.x]=cnt, g[cnt].pb(e.x), g[e.x].pb(cnt);
          if(v[e.y]!=cnt) v[e.y]=cnt, g[cnt].pb(e.y), g[e.y].pb(cnt);
            
          if(e.x == x && e.y == to[i]) break;
        }
      }
    }
    else if(dfn[to[i]] < low[x]){
      S.push((lines){x,to[i]});
      low[x]=dfn[to[i]];
    }
}

void dfs(int x,int fa){
  if(x<=n){
      for(int i:g[x]) if(i!=fa)
        dfs(i,x), ans += siz[x] * (ll)siz[i], siz[x] += siz[i];
      ans+=siz[x] * (ll)(nn - siz[x] - 1);
      siz[x]++;
  }
  else{
      int sz=g[x].size()-2;
      for(int i:g[x]) if(i!=fa)
        dfs(i,x), ans += siz[x] * (ll)siz[i] * (ll)sz, siz[x] += siz[i];
      ans += siz[x] * (ll)(nn - siz[x]) * (ll)sz;
  }
}

inline void solve(){
  for(int i=1; i<=n; i++) if(!dfn[i]){
    nn=0,tarjan(i,0);
    dfs(i,0);
  }
}

int main(){
  scanf("%d %d", &n, &m); cnt=n;
  for(int i=1,uu,vv;i<=m;i++){
    scanf("%d %d", &uu, &vv);
    add(uu,vv), add(vv,uu);
  }
  solve(); 
  printf("%lld\n",ans<<1);
  return 0;
}

Compilation message

count_triplets.cpp: In function 'void tarjan(int, int)':
count_triplets.cpp:19:34: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   for(int i=hd[x]; i; i=ne[i]) if(to[i]!=fa)
                                  ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m); cnt=n;
   ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &uu, &vv);
     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 9 ms 5308 KB Output is correct
4 Correct 8 ms 5332 KB Output is correct
5 Correct 7 ms 5332 KB Output is correct
6 Correct 8 ms 5332 KB Output is correct
7 Correct 8 ms 5332 KB Output is correct
8 Correct 10 ms 5332 KB Output is correct
9 Correct 9 ms 5332 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 8 ms 5352 KB Output is correct
12 Correct 8 ms 5352 KB Output is correct
13 Correct 8 ms 5352 KB Output is correct
14 Correct 9 ms 5352 KB Output is correct
15 Correct 8 ms 5412 KB Output is correct
16 Correct 8 ms 5412 KB Output is correct
17 Correct 8 ms 5412 KB Output is correct
18 Correct 7 ms 5412 KB Output is correct
19 Correct 8 ms 5412 KB Output is correct
20 Correct 8 ms 5412 KB Output is correct
21 Correct 8 ms 5412 KB Output is correct
22 Correct 9 ms 5412 KB Output is correct
23 Correct 7 ms 5412 KB Output is correct
24 Correct 9 ms 5412 KB Output is correct
25 Correct 8 ms 5412 KB Output is correct
26 Correct 8 ms 5412 KB Output is correct
27 Correct 8 ms 5412 KB Output is correct
28 Correct 7 ms 5412 KB Output is correct
29 Correct 8 ms 5412 KB Output is correct
30 Correct 8 ms 5412 KB Output is correct
31 Correct 6 ms 5412 KB Output is correct
32 Correct 9 ms 5412 KB Output is correct
33 Correct 8 ms 5412 KB Output is correct
34 Correct 8 ms 5412 KB Output is correct
35 Correct 8 ms 5412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 9 ms 5308 KB Output is correct
4 Correct 8 ms 5332 KB Output is correct
5 Correct 7 ms 5332 KB Output is correct
6 Correct 8 ms 5332 KB Output is correct
7 Correct 8 ms 5332 KB Output is correct
8 Correct 10 ms 5332 KB Output is correct
9 Correct 9 ms 5332 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 8 ms 5352 KB Output is correct
12 Correct 8 ms 5352 KB Output is correct
13 Correct 8 ms 5352 KB Output is correct
14 Correct 9 ms 5352 KB Output is correct
15 Correct 8 ms 5412 KB Output is correct
16 Correct 8 ms 5412 KB Output is correct
17 Correct 8 ms 5412 KB Output is correct
18 Correct 7 ms 5412 KB Output is correct
19 Correct 8 ms 5412 KB Output is correct
20 Correct 8 ms 5412 KB Output is correct
21 Correct 8 ms 5412 KB Output is correct
22 Correct 9 ms 5412 KB Output is correct
23 Correct 7 ms 5412 KB Output is correct
24 Correct 9 ms 5412 KB Output is correct
25 Correct 8 ms 5412 KB Output is correct
26 Correct 8 ms 5412 KB Output is correct
27 Correct 8 ms 5412 KB Output is correct
28 Correct 7 ms 5412 KB Output is correct
29 Correct 8 ms 5412 KB Output is correct
30 Correct 8 ms 5412 KB Output is correct
31 Correct 6 ms 5412 KB Output is correct
32 Correct 9 ms 5412 KB Output is correct
33 Correct 8 ms 5412 KB Output is correct
34 Correct 8 ms 5412 KB Output is correct
35 Correct 8 ms 5412 KB Output is correct
36 Correct 8 ms 5516 KB Output is correct
37 Correct 8 ms 5516 KB Output is correct
38 Correct 9 ms 5516 KB Output is correct
39 Correct 8 ms 5516 KB Output is correct
40 Correct 9 ms 5516 KB Output is correct
41 Correct 9 ms 5516 KB Output is correct
42 Correct 8 ms 5516 KB Output is correct
43 Correct 9 ms 5516 KB Output is correct
44 Correct 7 ms 5516 KB Output is correct
45 Correct 9 ms 5516 KB Output is correct
46 Correct 9 ms 5516 KB Output is correct
47 Correct 8 ms 5556 KB Output is correct
48 Correct 8 ms 5556 KB Output is correct
49 Correct 8 ms 5556 KB Output is correct
50 Correct 7 ms 5556 KB Output is correct
51 Correct 8 ms 5556 KB Output is correct
52 Correct 10 ms 5556 KB Output is correct
53 Correct 8 ms 5556 KB Output is correct
54 Correct 8 ms 5556 KB Output is correct
55 Correct 8 ms 5556 KB Output is correct
56 Correct 8 ms 5556 KB Output is correct
57 Correct 8 ms 5556 KB Output is correct
58 Correct 9 ms 5556 KB Output is correct
59 Correct 8 ms 5556 KB Output is correct
60 Correct 8 ms 5556 KB Output is correct
61 Correct 10 ms 5612 KB Output is correct
62 Correct 8 ms 5612 KB Output is correct
63 Correct 8 ms 5612 KB Output is correct
64 Correct 8 ms 5612 KB Output is correct
65 Correct 8 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 15896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15896 KB Output is correct
2 Correct 8 ms 15896 KB Output is correct
3 Correct 8 ms 15896 KB Output is correct
4 Correct 8 ms 15896 KB Output is correct
5 Correct 10 ms 15896 KB Output is correct
6 Correct 9 ms 15896 KB Output is correct
7 Correct 10 ms 15896 KB Output is correct
8 Correct 8 ms 15896 KB Output is correct
9 Correct 7 ms 15896 KB Output is correct
10 Correct 9 ms 15896 KB Output is correct
11 Correct 10 ms 15896 KB Output is correct
12 Correct 9 ms 15896 KB Output is correct
13 Correct 8 ms 15896 KB Output is correct
14 Correct 10 ms 15896 KB Output is correct
15 Correct 10 ms 15896 KB Output is correct
16 Correct 9 ms 15896 KB Output is correct
17 Correct 8 ms 15896 KB Output is correct
18 Correct 10 ms 15896 KB Output is correct
19 Correct 7 ms 15896 KB Output is correct
20 Correct 8 ms 15896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 16208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16208 KB Output is correct
2 Correct 9 ms 16208 KB Output is correct
3 Correct 8 ms 16208 KB Output is correct
4 Correct 9 ms 16208 KB Output is correct
5 Correct 14 ms 16208 KB Output is correct
6 Correct 8 ms 16208 KB Output is correct
7 Correct 7 ms 16208 KB Output is correct
8 Correct 10 ms 16208 KB Output is correct
9 Correct 10 ms 16208 KB Output is correct
10 Correct 9 ms 16208 KB Output is correct
11 Correct 9 ms 16208 KB Output is correct
12 Correct 10 ms 16208 KB Output is correct
13 Correct 8 ms 16208 KB Output is correct
14 Correct 7 ms 16208 KB Output is correct
15 Correct 8 ms 16208 KB Output is correct
16 Correct 10 ms 16208 KB Output is correct
17 Correct 9 ms 16208 KB Output is correct
18 Correct 9 ms 16208 KB Output is correct
19 Correct 8 ms 16208 KB Output is correct
20 Correct 10 ms 16208 KB Output is correct
21 Correct 10 ms 16208 KB Output is correct
22 Correct 8 ms 16208 KB Output is correct
23 Correct 8 ms 16208 KB Output is correct
24 Correct 9 ms 16208 KB Output is correct
25 Correct 7 ms 16208 KB Output is correct
26 Correct 9 ms 16208 KB Output is correct
27 Correct 9 ms 16208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 16392 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 9 ms 5308 KB Output is correct
4 Correct 8 ms 5332 KB Output is correct
5 Correct 7 ms 5332 KB Output is correct
6 Correct 8 ms 5332 KB Output is correct
7 Correct 8 ms 5332 KB Output is correct
8 Correct 10 ms 5332 KB Output is correct
9 Correct 9 ms 5332 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 8 ms 5352 KB Output is correct
12 Correct 8 ms 5352 KB Output is correct
13 Correct 8 ms 5352 KB Output is correct
14 Correct 9 ms 5352 KB Output is correct
15 Correct 8 ms 5412 KB Output is correct
16 Correct 8 ms 5412 KB Output is correct
17 Correct 8 ms 5412 KB Output is correct
18 Correct 7 ms 5412 KB Output is correct
19 Correct 8 ms 5412 KB Output is correct
20 Correct 8 ms 5412 KB Output is correct
21 Correct 8 ms 5412 KB Output is correct
22 Correct 9 ms 5412 KB Output is correct
23 Correct 7 ms 5412 KB Output is correct
24 Correct 9 ms 5412 KB Output is correct
25 Correct 8 ms 5412 KB Output is correct
26 Correct 8 ms 5412 KB Output is correct
27 Correct 8 ms 5412 KB Output is correct
28 Correct 7 ms 5412 KB Output is correct
29 Correct 8 ms 5412 KB Output is correct
30 Correct 8 ms 5412 KB Output is correct
31 Correct 6 ms 5412 KB Output is correct
32 Correct 9 ms 5412 KB Output is correct
33 Correct 8 ms 5412 KB Output is correct
34 Correct 8 ms 5412 KB Output is correct
35 Correct 8 ms 5412 KB Output is correct
36 Correct 8 ms 5516 KB Output is correct
37 Correct 8 ms 5516 KB Output is correct
38 Correct 9 ms 5516 KB Output is correct
39 Correct 8 ms 5516 KB Output is correct
40 Correct 9 ms 5516 KB Output is correct
41 Correct 9 ms 5516 KB Output is correct
42 Correct 8 ms 5516 KB Output is correct
43 Correct 9 ms 5516 KB Output is correct
44 Correct 7 ms 5516 KB Output is correct
45 Correct 9 ms 5516 KB Output is correct
46 Correct 9 ms 5516 KB Output is correct
47 Correct 8 ms 5556 KB Output is correct
48 Correct 8 ms 5556 KB Output is correct
49 Correct 8 ms 5556 KB Output is correct
50 Correct 7 ms 5556 KB Output is correct
51 Correct 8 ms 5556 KB Output is correct
52 Correct 10 ms 5556 KB Output is correct
53 Correct 8 ms 5556 KB Output is correct
54 Correct 8 ms 5556 KB Output is correct
55 Correct 8 ms 5556 KB Output is correct
56 Correct 8 ms 5556 KB Output is correct
57 Correct 8 ms 5556 KB Output is correct
58 Correct 9 ms 5556 KB Output is correct
59 Correct 8 ms 5556 KB Output is correct
60 Correct 8 ms 5556 KB Output is correct
61 Correct 10 ms 5612 KB Output is correct
62 Correct 8 ms 5612 KB Output is correct
63 Correct 8 ms 5612 KB Output is correct
64 Correct 8 ms 5612 KB Output is correct
65 Correct 8 ms 5612 KB Output is correct
66 Correct 9 ms 16392 KB Output is correct
67 Correct 8 ms 16392 KB Output is correct
68 Correct 10 ms 16392 KB Output is correct
69 Correct 9 ms 16392 KB Output is correct
70 Correct 10 ms 16392 KB Output is correct
71 Correct 8 ms 16392 KB Output is correct
72 Correct 7 ms 16392 KB Output is correct
73 Correct 9 ms 16392 KB Output is correct
74 Correct 9 ms 16392 KB Output is correct
75 Correct 7 ms 16392 KB Output is correct
76 Correct 9 ms 16392 KB Output is correct
77 Correct 11 ms 16392 KB Output is correct
78 Correct 9 ms 16392 KB Output is correct
79 Correct 9 ms 16392 KB Output is correct
80 Correct 12 ms 16392 KB Output is correct
81 Correct 8 ms 16392 KB Output is correct
82 Correct 9 ms 16392 KB Output is correct
83 Correct 9 ms 16392 KB Output is correct
84 Correct 8 ms 16392 KB Output is correct
85 Correct 9 ms 16392 KB Output is correct
86 Correct 8 ms 16392 KB Output is correct
87 Correct 9 ms 16392 KB Output is correct
88 Correct 8 ms 16392 KB Output is correct
89 Correct 7 ms 16392 KB Output is correct
90 Correct 8 ms 16392 KB Output is correct
91 Correct 12 ms 16392 KB Output is correct
92 Correct 8 ms 16392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 9 ms 5308 KB Output is correct
4 Correct 8 ms 5332 KB Output is correct
5 Correct 7 ms 5332 KB Output is correct
6 Correct 8 ms 5332 KB Output is correct
7 Correct 8 ms 5332 KB Output is correct
8 Correct 10 ms 5332 KB Output is correct
9 Correct 9 ms 5332 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 8 ms 5352 KB Output is correct
12 Correct 8 ms 5352 KB Output is correct
13 Correct 8 ms 5352 KB Output is correct
14 Correct 9 ms 5352 KB Output is correct
15 Correct 8 ms 5412 KB Output is correct
16 Correct 8 ms 5412 KB Output is correct
17 Correct 8 ms 5412 KB Output is correct
18 Correct 7 ms 5412 KB Output is correct
19 Correct 8 ms 5412 KB Output is correct
20 Correct 8 ms 5412 KB Output is correct
21 Correct 8 ms 5412 KB Output is correct
22 Correct 9 ms 5412 KB Output is correct
23 Correct 7 ms 5412 KB Output is correct
24 Correct 9 ms 5412 KB Output is correct
25 Correct 8 ms 5412 KB Output is correct
26 Correct 8 ms 5412 KB Output is correct
27 Correct 8 ms 5412 KB Output is correct
28 Correct 7 ms 5412 KB Output is correct
29 Correct 8 ms 5412 KB Output is correct
30 Correct 8 ms 5412 KB Output is correct
31 Correct 6 ms 5412 KB Output is correct
32 Correct 9 ms 5412 KB Output is correct
33 Correct 8 ms 5412 KB Output is correct
34 Correct 8 ms 5412 KB Output is correct
35 Correct 8 ms 5412 KB Output is correct
36 Correct 8 ms 5516 KB Output is correct
37 Correct 8 ms 5516 KB Output is correct
38 Correct 9 ms 5516 KB Output is correct
39 Correct 8 ms 5516 KB Output is correct
40 Correct 9 ms 5516 KB Output is correct
41 Correct 9 ms 5516 KB Output is correct
42 Correct 8 ms 5516 KB Output is correct
43 Correct 9 ms 5516 KB Output is correct
44 Correct 7 ms 5516 KB Output is correct
45 Correct 9 ms 5516 KB Output is correct
46 Correct 9 ms 5516 KB Output is correct
47 Correct 8 ms 5556 KB Output is correct
48 Correct 8 ms 5556 KB Output is correct
49 Correct 8 ms 5556 KB Output is correct
50 Correct 7 ms 5556 KB Output is correct
51 Correct 8 ms 5556 KB Output is correct
52 Correct 10 ms 5556 KB Output is correct
53 Correct 8 ms 5556 KB Output is correct
54 Correct 8 ms 5556 KB Output is correct
55 Correct 8 ms 5556 KB Output is correct
56 Correct 8 ms 5556 KB Output is correct
57 Correct 8 ms 5556 KB Output is correct
58 Correct 9 ms 5556 KB Output is correct
59 Correct 8 ms 5556 KB Output is correct
60 Correct 8 ms 5556 KB Output is correct
61 Correct 10 ms 5612 KB Output is correct
62 Correct 8 ms 5612 KB Output is correct
63 Correct 8 ms 5612 KB Output is correct
64 Correct 8 ms 5612 KB Output is correct
65 Correct 8 ms 5612 KB Output is correct
66 Runtime error 55 ms 15896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
67 Halted 0 ms 0 KB -