Submission #166710

# Submission time Handle Problem Language Result Execution time Memory
166710 2019-12-03T14:02:27 Z combi1k1 Duathlon (APIO18_duathlon) C++14
24 / 100
171 ms 29040 KB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long

const int   N   = 1e5 + 1;

vector<int> g[N];
vector<int> a[N + N];

void addEdge(int u,int v)   {
    a[u].push_back(v);
    a[v].push_back(u);
    //cerr << u << " " << v << "\n";
}

int dfn[N], low[N];
int nCh[N + N];
int tot, siz;
int ver = N;
ll  ans = 0;

stack<int>  st;

void dfs(int u,int p)   {
    siz++;
    tot++;
    dfn[u] = tot;
    low[u] = tot;

    st.push(u);

    for(int v : g[u])   if (v != p) {
        if (dfn[v])     low[u] = min(low[u],dfn[v]);
        if(!dfn[v]) {
            dfs(v,u);   low[u] = min(low[u],low[v]);
            if (low[v] >= dfn[u])   {
                ver++;  addEdge(u,ver);
                int z;
                while (z != v)  {
                    z = st.top();   st.pop();
                    addEdge(z,ver);
                }
            }
        }
    }
}
void cal(int u,int p)   {
    if (u < N)
        nCh[u] = 1;

    for(int v : a[u])   if (v ^ p)  {
        cal(v,u);
        nCh[u] += nCh[v];
    }
    if (u < N)  return;

    for(int v : a[u])   {
        int T_T;
        if (v ^ p)  T_T = nCh[v];
        else        T_T = siz - nCh[u];

        ans -= 1ll * T_T * (T_T - 1) * (a[u].size() - 1);
    }
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int m;  cin >> m;

    for(int i = 0 ; i < m ; ++i)    {
        int x;  cin >> x;
        int y;  cin >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 1 ; i <= n ; ++i)   if(!dfn[i]) {
        siz = 0;
        dfs(i,0);   ans += 1ll * siz * (siz - 1) * (siz - 2);
        cal(i,0);
    }

    cout << ans << endl;
}
/*
4 4
1 2
2 3
3 4
4 2
*/
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 8 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 10 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7416 KB Output is correct
14 Correct 8 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7416 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7420 KB Output is correct
22 Correct 9 ms 7416 KB Output is correct
23 Correct 21 ms 7416 KB Output is correct
24 Correct 9 ms 7416 KB Output is correct
25 Correct 10 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7416 KB Output is correct
28 Correct 8 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7380 KB Output is correct
31 Correct 9 ms 7420 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 10 ms 7416 KB Output is correct
34 Correct 9 ms 7416 KB Output is correct
35 Correct 9 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 8 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 10 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7416 KB Output is correct
14 Correct 8 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7416 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7420 KB Output is correct
22 Correct 9 ms 7416 KB Output is correct
23 Correct 21 ms 7416 KB Output is correct
24 Correct 9 ms 7416 KB Output is correct
25 Correct 10 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7416 KB Output is correct
28 Correct 8 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7380 KB Output is correct
31 Correct 9 ms 7420 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 10 ms 7416 KB Output is correct
34 Correct 9 ms 7416 KB Output is correct
35 Correct 9 ms 7416 KB Output is correct
36 Correct 9 ms 7416 KB Output is correct
37 Correct 9 ms 7416 KB Output is correct
38 Correct 9 ms 7416 KB Output is correct
39 Correct 9 ms 7416 KB Output is correct
40 Correct 9 ms 7416 KB Output is correct
41 Correct 9 ms 7416 KB Output is correct
42 Correct 9 ms 7416 KB Output is correct
43 Correct 9 ms 7416 KB Output is correct
44 Correct 9 ms 7416 KB Output is correct
45 Correct 9 ms 7416 KB Output is correct
46 Correct 9 ms 7416 KB Output is correct
47 Correct 9 ms 7420 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Correct 9 ms 7416 KB Output is correct
50 Correct 9 ms 7416 KB Output is correct
51 Correct 8 ms 7416 KB Output is correct
52 Correct 8 ms 7416 KB Output is correct
53 Correct 9 ms 7416 KB Output is correct
54 Correct 9 ms 7416 KB Output is correct
55 Correct 9 ms 7416 KB Output is correct
56 Correct 9 ms 7416 KB Output is correct
57 Correct 9 ms 7416 KB Output is correct
58 Correct 9 ms 7416 KB Output is correct
59 Correct 8 ms 7416 KB Output is correct
60 Correct 9 ms 7416 KB Output is correct
61 Correct 8 ms 7416 KB Output is correct
62 Correct 8 ms 7416 KB Output is correct
63 Correct 8 ms 7416 KB Output is correct
64 Correct 8 ms 7416 KB Output is correct
65 Correct 9 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 29040 KB Output is correct
2 Correct 119 ms 29040 KB Output is correct
3 Correct 136 ms 24564 KB Output is correct
4 Correct 136 ms 26616 KB Output is correct
5 Correct 133 ms 21716 KB Output is correct
6 Correct 171 ms 23476 KB Output is correct
7 Correct 156 ms 21368 KB Output is correct
8 Correct 153 ms 21964 KB Output is correct
9 Correct 128 ms 19916 KB Output is correct
10 Correct 138 ms 20444 KB Output is correct
11 Correct 162 ms 17656 KB Output is correct
12 Correct 107 ms 17656 KB Output is correct
13 Correct 95 ms 17372 KB Output is correct
14 Correct 102 ms 17100 KB Output is correct
15 Correct 77 ms 15992 KB Output is correct
16 Correct 75 ms 15776 KB Output is correct
17 Correct 12 ms 9080 KB Output is correct
18 Correct 14 ms 9080 KB Output is correct
19 Correct 12 ms 9000 KB Output is correct
20 Correct 12 ms 9080 KB Output is correct
21 Correct 12 ms 8952 KB Output is correct
22 Correct 12 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Incorrect 9 ms 7672 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 154 ms 19832 KB Output is correct
2 Correct 153 ms 19820 KB Output is correct
3 Incorrect 156 ms 19832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7672 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
11 Correct 9 ms 7544 KB Output is correct
12 Incorrect 10 ms 7544 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 138 ms 19812 KB Output is correct
2 Correct 147 ms 19668 KB Output is correct
3 Correct 149 ms 19320 KB Output is correct
4 Incorrect 147 ms 18808 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 8 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 10 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7416 KB Output is correct
14 Correct 8 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7416 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7420 KB Output is correct
22 Correct 9 ms 7416 KB Output is correct
23 Correct 21 ms 7416 KB Output is correct
24 Correct 9 ms 7416 KB Output is correct
25 Correct 10 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7416 KB Output is correct
28 Correct 8 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7380 KB Output is correct
31 Correct 9 ms 7420 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 10 ms 7416 KB Output is correct
34 Correct 9 ms 7416 KB Output is correct
35 Correct 9 ms 7416 KB Output is correct
36 Correct 9 ms 7416 KB Output is correct
37 Correct 9 ms 7416 KB Output is correct
38 Correct 9 ms 7416 KB Output is correct
39 Correct 9 ms 7416 KB Output is correct
40 Correct 9 ms 7416 KB Output is correct
41 Correct 9 ms 7416 KB Output is correct
42 Correct 9 ms 7416 KB Output is correct
43 Correct 9 ms 7416 KB Output is correct
44 Correct 9 ms 7416 KB Output is correct
45 Correct 9 ms 7416 KB Output is correct
46 Correct 9 ms 7416 KB Output is correct
47 Correct 9 ms 7420 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Correct 9 ms 7416 KB Output is correct
50 Correct 9 ms 7416 KB Output is correct
51 Correct 8 ms 7416 KB Output is correct
52 Correct 8 ms 7416 KB Output is correct
53 Correct 9 ms 7416 KB Output is correct
54 Correct 9 ms 7416 KB Output is correct
55 Correct 9 ms 7416 KB Output is correct
56 Correct 9 ms 7416 KB Output is correct
57 Correct 9 ms 7416 KB Output is correct
58 Correct 9 ms 7416 KB Output is correct
59 Correct 8 ms 7416 KB Output is correct
60 Correct 9 ms 7416 KB Output is correct
61 Correct 8 ms 7416 KB Output is correct
62 Correct 8 ms 7416 KB Output is correct
63 Correct 8 ms 7416 KB Output is correct
64 Correct 8 ms 7416 KB Output is correct
65 Correct 9 ms 7416 KB Output is correct
66 Correct 9 ms 7416 KB Output is correct
67 Correct 9 ms 7416 KB Output is correct
68 Correct 9 ms 7544 KB Output is correct
69 Correct 10 ms 7548 KB Output is correct
70 Correct 9 ms 7544 KB Output is correct
71 Correct 9 ms 7416 KB Output is correct
72 Correct 11 ms 7512 KB Output is correct
73 Correct 9 ms 7544 KB Output is correct
74 Correct 9 ms 7544 KB Output is correct
75 Correct 9 ms 7416 KB Output is correct
76 Correct 10 ms 7416 KB Output is correct
77 Correct 9 ms 7544 KB Output is correct
78 Correct 9 ms 7544 KB Output is correct
79 Correct 9 ms 7544 KB Output is correct
80 Correct 9 ms 7544 KB Output is correct
81 Correct 9 ms 7544 KB Output is correct
82 Correct 9 ms 7544 KB Output is correct
83 Correct 9 ms 7544 KB Output is correct
84 Incorrect 10 ms 7544 KB Output isn't correct
85 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 8 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 10 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7416 KB Output is correct
14 Correct 8 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7416 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7420 KB Output is correct
22 Correct 9 ms 7416 KB Output is correct
23 Correct 21 ms 7416 KB Output is correct
24 Correct 9 ms 7416 KB Output is correct
25 Correct 10 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7416 KB Output is correct
28 Correct 8 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7380 KB Output is correct
31 Correct 9 ms 7420 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 10 ms 7416 KB Output is correct
34 Correct 9 ms 7416 KB Output is correct
35 Correct 9 ms 7416 KB Output is correct
36 Correct 9 ms 7416 KB Output is correct
37 Correct 9 ms 7416 KB Output is correct
38 Correct 9 ms 7416 KB Output is correct
39 Correct 9 ms 7416 KB Output is correct
40 Correct 9 ms 7416 KB Output is correct
41 Correct 9 ms 7416 KB Output is correct
42 Correct 9 ms 7416 KB Output is correct
43 Correct 9 ms 7416 KB Output is correct
44 Correct 9 ms 7416 KB Output is correct
45 Correct 9 ms 7416 KB Output is correct
46 Correct 9 ms 7416 KB Output is correct
47 Correct 9 ms 7420 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Correct 9 ms 7416 KB Output is correct
50 Correct 9 ms 7416 KB Output is correct
51 Correct 8 ms 7416 KB Output is correct
52 Correct 8 ms 7416 KB Output is correct
53 Correct 9 ms 7416 KB Output is correct
54 Correct 9 ms 7416 KB Output is correct
55 Correct 9 ms 7416 KB Output is correct
56 Correct 9 ms 7416 KB Output is correct
57 Correct 9 ms 7416 KB Output is correct
58 Correct 9 ms 7416 KB Output is correct
59 Correct 8 ms 7416 KB Output is correct
60 Correct 9 ms 7416 KB Output is correct
61 Correct 8 ms 7416 KB Output is correct
62 Correct 8 ms 7416 KB Output is correct
63 Correct 8 ms 7416 KB Output is correct
64 Correct 8 ms 7416 KB Output is correct
65 Correct 9 ms 7416 KB Output is correct
66 Correct 118 ms 29040 KB Output is correct
67 Correct 119 ms 29040 KB Output is correct
68 Correct 136 ms 24564 KB Output is correct
69 Correct 136 ms 26616 KB Output is correct
70 Correct 133 ms 21716 KB Output is correct
71 Correct 171 ms 23476 KB Output is correct
72 Correct 156 ms 21368 KB Output is correct
73 Correct 153 ms 21964 KB Output is correct
74 Correct 128 ms 19916 KB Output is correct
75 Correct 138 ms 20444 KB Output is correct
76 Correct 162 ms 17656 KB Output is correct
77 Correct 107 ms 17656 KB Output is correct
78 Correct 95 ms 17372 KB Output is correct
79 Correct 102 ms 17100 KB Output is correct
80 Correct 77 ms 15992 KB Output is correct
81 Correct 75 ms 15776 KB Output is correct
82 Correct 12 ms 9080 KB Output is correct
83 Correct 14 ms 9080 KB Output is correct
84 Correct 12 ms 9000 KB Output is correct
85 Correct 12 ms 9080 KB Output is correct
86 Correct 12 ms 8952 KB Output is correct
87 Correct 12 ms 8952 KB Output is correct
88 Correct 9 ms 7544 KB Output is correct
89 Correct 9 ms 7544 KB Output is correct
90 Correct 9 ms 7544 KB Output is correct
91 Incorrect 9 ms 7672 KB Output isn't correct
92 Halted 0 ms 0 KB -