Submission #60163

# Submission time Handle Problem Language Result Execution time Memory
60163 2018-07-23T19:44:57 Z duality Duathlon (APIO18_duathlon) C++11
49 / 100
1000 ms 30056 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int LLI;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

vi adjList[100000];
int disc[100000],low[100000],art[100000],num = 0;
vi com[100000];
vpii S;
int bcc = 0;
int doDFS(int u,int p) {
    int i,c = 0;
    disc[u] = low[u] = num++;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (disc[v] == -1) {
            c++;
            S.pb(mp(u,v));
            doDFS(v,u);
            low[u] = min(low[u],low[v]);
            if (((p == -1) && (c > 1)) || ((p != -1) && (low[v] >= disc[u]))) {
                art[u] = 1;
                while (1) {
                    int uu = S.back().first,vv = S.back().second;
                    S.pop_back();
                    com[bcc].pb(uu),com[bcc].pb(vv);
                    if ((u == uu) && (v == vv)) break;
                }
                bcc++;
            }
        }
        else if ((v != p) && (disc[v] < disc[u])) low[u] = min(low[u],disc[v]),S.pb(mp(u,v));
    }
    return 0;
}
vi adjList2[200000];
LLI ans = 0;
int doDFS2(int u,int p,int s,int sum) {
    int i;
    if (u < bcc) {
        sum += com[u].size()-1;
        if (u != s) ans += (LLI) (com[s].size()-1)*(com[u].size()-1)*(sum-1);
    }
    for (i = 0; i < adjList2[u].size(); i++) {
        int v = adjList2[u][i];
        if (v != p) doDFS2(v,u,s,sum);
    }
    return 0;
}
int main() {
    int i;
    int n,m,u,v;
    scanf("%d %d",&n,&m);
    for (i = 0; i < m; i++) {
        scanf("%d %d",&u,&v);
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
    }

    int j;
    for (i = 0; i < n; i++) disc[i] = low[i] = -1;
    for (i = 0; i < n; i++) {
        if (disc[i] == -1) {
            doDFS(i,-1);
            if (!S.empty()) {
                while (!S.empty()) {
                    int u = S.back().first,v = S.back().second;
                    S.pop_back();
                    com[bcc].pb(u),com[bcc].pb(v);
                }
                bcc++;
            }
        }
    }
    for (i = 0; i < bcc; i++) {
        sort(com[i].begin(),com[i].end());
        com[i].resize(unique(com[i].begin(),com[i].end())-com[i].begin());
        for (j = 0; j < com[i].size(); j++) {
            if (art[com[i][j]]) {
                adjList2[i].pb(com[i][j]+bcc);
                adjList2[com[i][j]+bcc].pb(i);
            }
        }
        ans += com[i].size()*(com[i].size()-1)*(com[i].size()-2);
    }
    for (i = 0; i < bcc; i++) doDFS2(i,-1,i,0);
    printf("%lld\n",ans);

    return 0;
}

Compilation message

count_triplets.cpp: In function 'int doDFS(int, int)':
count_triplets.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
count_triplets.cpp: In function 'int doDFS2(int, int, int, int)':
count_triplets.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList2[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:83:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < com[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~
count_triplets.cpp:57:10: 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:59:14: 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 14 ms 9852 KB Output is correct
2 Correct 12 ms 9852 KB Output is correct
3 Correct 11 ms 9852 KB Output is correct
4 Correct 11 ms 9852 KB Output is correct
5 Correct 16 ms 9896 KB Output is correct
6 Correct 12 ms 9896 KB Output is correct
7 Correct 14 ms 9896 KB Output is correct
8 Correct 12 ms 9896 KB Output is correct
9 Correct 14 ms 10132 KB Output is correct
10 Correct 12 ms 10132 KB Output is correct
11 Correct 13 ms 10132 KB Output is correct
12 Correct 13 ms 10132 KB Output is correct
13 Correct 18 ms 10132 KB Output is correct
14 Correct 14 ms 10132 KB Output is correct
15 Correct 15 ms 10132 KB Output is correct
16 Correct 11 ms 10132 KB Output is correct
17 Correct 11 ms 10132 KB Output is correct
18 Correct 13 ms 10132 KB Output is correct
19 Correct 12 ms 10132 KB Output is correct
20 Correct 11 ms 10132 KB Output is correct
21 Correct 12 ms 10132 KB Output is correct
22 Correct 12 ms 10132 KB Output is correct
23 Correct 13 ms 10132 KB Output is correct
24 Correct 12 ms 10132 KB Output is correct
25 Correct 12 ms 10132 KB Output is correct
26 Correct 14 ms 10132 KB Output is correct
27 Correct 12 ms 10132 KB Output is correct
28 Correct 14 ms 10132 KB Output is correct
29 Correct 13 ms 10132 KB Output is correct
30 Correct 12 ms 10132 KB Output is correct
31 Correct 13 ms 10132 KB Output is correct
32 Correct 12 ms 10132 KB Output is correct
33 Correct 12 ms 10132 KB Output is correct
34 Correct 13 ms 10156 KB Output is correct
35 Correct 13 ms 10156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9852 KB Output is correct
2 Correct 12 ms 9852 KB Output is correct
3 Correct 11 ms 9852 KB Output is correct
4 Correct 11 ms 9852 KB Output is correct
5 Correct 16 ms 9896 KB Output is correct
6 Correct 12 ms 9896 KB Output is correct
7 Correct 14 ms 9896 KB Output is correct
8 Correct 12 ms 9896 KB Output is correct
9 Correct 14 ms 10132 KB Output is correct
10 Correct 12 ms 10132 KB Output is correct
11 Correct 13 ms 10132 KB Output is correct
12 Correct 13 ms 10132 KB Output is correct
13 Correct 18 ms 10132 KB Output is correct
14 Correct 14 ms 10132 KB Output is correct
15 Correct 15 ms 10132 KB Output is correct
16 Correct 11 ms 10132 KB Output is correct
17 Correct 11 ms 10132 KB Output is correct
18 Correct 13 ms 10132 KB Output is correct
19 Correct 12 ms 10132 KB Output is correct
20 Correct 11 ms 10132 KB Output is correct
21 Correct 12 ms 10132 KB Output is correct
22 Correct 12 ms 10132 KB Output is correct
23 Correct 13 ms 10132 KB Output is correct
24 Correct 12 ms 10132 KB Output is correct
25 Correct 12 ms 10132 KB Output is correct
26 Correct 14 ms 10132 KB Output is correct
27 Correct 12 ms 10132 KB Output is correct
28 Correct 14 ms 10132 KB Output is correct
29 Correct 13 ms 10132 KB Output is correct
30 Correct 12 ms 10132 KB Output is correct
31 Correct 13 ms 10132 KB Output is correct
32 Correct 12 ms 10132 KB Output is correct
33 Correct 12 ms 10132 KB Output is correct
34 Correct 13 ms 10156 KB Output is correct
35 Correct 13 ms 10156 KB Output is correct
36 Correct 10 ms 10156 KB Output is correct
37 Correct 11 ms 10156 KB Output is correct
38 Correct 11 ms 10156 KB Output is correct
39 Correct 12 ms 10156 KB Output is correct
40 Correct 12 ms 10156 KB Output is correct
41 Correct 12 ms 10240 KB Output is correct
42 Correct 14 ms 10260 KB Output is correct
43 Correct 14 ms 10260 KB Output is correct
44 Correct 11 ms 10300 KB Output is correct
45 Correct 14 ms 10300 KB Output is correct
46 Correct 10 ms 10300 KB Output is correct
47 Correct 12 ms 10300 KB Output is correct
48 Correct 11 ms 10300 KB Output is correct
49 Correct 13 ms 10300 KB Output is correct
50 Correct 12 ms 10300 KB Output is correct
51 Correct 12 ms 10376 KB Output is correct
52 Correct 13 ms 10380 KB Output is correct
53 Correct 11 ms 10380 KB Output is correct
54 Correct 12 ms 10380 KB Output is correct
55 Correct 12 ms 10380 KB Output is correct
56 Correct 13 ms 10380 KB Output is correct
57 Correct 14 ms 10380 KB Output is correct
58 Correct 12 ms 10380 KB Output is correct
59 Correct 12 ms 10380 KB Output is correct
60 Correct 11 ms 10380 KB Output is correct
61 Correct 11 ms 10380 KB Output is correct
62 Correct 11 ms 10380 KB Output is correct
63 Correct 12 ms 10380 KB Output is correct
64 Correct 9 ms 10380 KB Output is correct
65 Correct 15 ms 10380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 28860 KB Output is correct
2 Correct 164 ms 30000 KB Output is correct
3 Execution timed out 1069 ms 30056 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 30056 KB Output is correct
2 Correct 46 ms 30056 KB Output is correct
3 Correct 39 ms 30056 KB Output is correct
4 Correct 54 ms 30056 KB Output is correct
5 Correct 52 ms 30056 KB Output is correct
6 Correct 47 ms 30056 KB Output is correct
7 Correct 50 ms 30056 KB Output is correct
8 Correct 56 ms 30056 KB Output is correct
9 Correct 55 ms 30056 KB Output is correct
10 Correct 33 ms 30056 KB Output is correct
11 Correct 31 ms 30056 KB Output is correct
12 Correct 24 ms 30056 KB Output is correct
13 Correct 16 ms 30056 KB Output is correct
14 Correct 14 ms 30056 KB Output is correct
15 Correct 14 ms 30056 KB Output is correct
16 Correct 13 ms 30056 KB Output is correct
17 Correct 36 ms 30056 KB Output is correct
18 Correct 24 ms 30056 KB Output is correct
19 Correct 25 ms 30056 KB Output is correct
20 Correct 23 ms 30056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 30056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 30056 KB Output is correct
2 Correct 38 ms 30056 KB Output is correct
3 Correct 30 ms 30056 KB Output is correct
4 Correct 28 ms 30056 KB Output is correct
5 Correct 20 ms 30056 KB Output is correct
6 Correct 17 ms 30056 KB Output is correct
7 Correct 17 ms 30056 KB Output is correct
8 Correct 14 ms 30056 KB Output is correct
9 Correct 14 ms 30056 KB Output is correct
10 Correct 13 ms 30056 KB Output is correct
11 Correct 14 ms 30056 KB Output is correct
12 Correct 37 ms 30056 KB Output is correct
13 Correct 32 ms 30056 KB Output is correct
14 Correct 33 ms 30056 KB Output is correct
15 Correct 27 ms 30056 KB Output is correct
16 Correct 22 ms 30056 KB Output is correct
17 Correct 18 ms 30056 KB Output is correct
18 Correct 13 ms 30056 KB Output is correct
19 Correct 12 ms 30056 KB Output is correct
20 Correct 14 ms 30056 KB Output is correct
21 Correct 36 ms 30056 KB Output is correct
22 Correct 26 ms 30056 KB Output is correct
23 Correct 24 ms 30056 KB Output is correct
24 Correct 22 ms 30056 KB Output is correct
25 Correct 12 ms 30056 KB Output is correct
26 Correct 13 ms 30056 KB Output is correct
27 Correct 12 ms 30056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 30056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9852 KB Output is correct
2 Correct 12 ms 9852 KB Output is correct
3 Correct 11 ms 9852 KB Output is correct
4 Correct 11 ms 9852 KB Output is correct
5 Correct 16 ms 9896 KB Output is correct
6 Correct 12 ms 9896 KB Output is correct
7 Correct 14 ms 9896 KB Output is correct
8 Correct 12 ms 9896 KB Output is correct
9 Correct 14 ms 10132 KB Output is correct
10 Correct 12 ms 10132 KB Output is correct
11 Correct 13 ms 10132 KB Output is correct
12 Correct 13 ms 10132 KB Output is correct
13 Correct 18 ms 10132 KB Output is correct
14 Correct 14 ms 10132 KB Output is correct
15 Correct 15 ms 10132 KB Output is correct
16 Correct 11 ms 10132 KB Output is correct
17 Correct 11 ms 10132 KB Output is correct
18 Correct 13 ms 10132 KB Output is correct
19 Correct 12 ms 10132 KB Output is correct
20 Correct 11 ms 10132 KB Output is correct
21 Correct 12 ms 10132 KB Output is correct
22 Correct 12 ms 10132 KB Output is correct
23 Correct 13 ms 10132 KB Output is correct
24 Correct 12 ms 10132 KB Output is correct
25 Correct 12 ms 10132 KB Output is correct
26 Correct 14 ms 10132 KB Output is correct
27 Correct 12 ms 10132 KB Output is correct
28 Correct 14 ms 10132 KB Output is correct
29 Correct 13 ms 10132 KB Output is correct
30 Correct 12 ms 10132 KB Output is correct
31 Correct 13 ms 10132 KB Output is correct
32 Correct 12 ms 10132 KB Output is correct
33 Correct 12 ms 10132 KB Output is correct
34 Correct 13 ms 10156 KB Output is correct
35 Correct 13 ms 10156 KB Output is correct
36 Correct 10 ms 10156 KB Output is correct
37 Correct 11 ms 10156 KB Output is correct
38 Correct 11 ms 10156 KB Output is correct
39 Correct 12 ms 10156 KB Output is correct
40 Correct 12 ms 10156 KB Output is correct
41 Correct 12 ms 10240 KB Output is correct
42 Correct 14 ms 10260 KB Output is correct
43 Correct 14 ms 10260 KB Output is correct
44 Correct 11 ms 10300 KB Output is correct
45 Correct 14 ms 10300 KB Output is correct
46 Correct 10 ms 10300 KB Output is correct
47 Correct 12 ms 10300 KB Output is correct
48 Correct 11 ms 10300 KB Output is correct
49 Correct 13 ms 10300 KB Output is correct
50 Correct 12 ms 10300 KB Output is correct
51 Correct 12 ms 10376 KB Output is correct
52 Correct 13 ms 10380 KB Output is correct
53 Correct 11 ms 10380 KB Output is correct
54 Correct 12 ms 10380 KB Output is correct
55 Correct 12 ms 10380 KB Output is correct
56 Correct 13 ms 10380 KB Output is correct
57 Correct 14 ms 10380 KB Output is correct
58 Correct 12 ms 10380 KB Output is correct
59 Correct 12 ms 10380 KB Output is correct
60 Correct 11 ms 10380 KB Output is correct
61 Correct 11 ms 10380 KB Output is correct
62 Correct 11 ms 10380 KB Output is correct
63 Correct 12 ms 10380 KB Output is correct
64 Correct 9 ms 10380 KB Output is correct
65 Correct 15 ms 10380 KB Output is correct
66 Correct 10 ms 30056 KB Output is correct
67 Correct 12 ms 30056 KB Output is correct
68 Correct 16 ms 30056 KB Output is correct
69 Correct 11 ms 30056 KB Output is correct
70 Correct 11 ms 30056 KB Output is correct
71 Correct 15 ms 30056 KB Output is correct
72 Correct 15 ms 30056 KB Output is correct
73 Correct 13 ms 30056 KB Output is correct
74 Correct 14 ms 30056 KB Output is correct
75 Correct 14 ms 30056 KB Output is correct
76 Correct 12 ms 30056 KB Output is correct
77 Correct 22 ms 30056 KB Output is correct
78 Correct 18 ms 30056 KB Output is correct
79 Correct 15 ms 30056 KB Output is correct
80 Correct 14 ms 30056 KB Output is correct
81 Correct 16 ms 30056 KB Output is correct
82 Correct 13 ms 30056 KB Output is correct
83 Correct 13 ms 30056 KB Output is correct
84 Correct 18 ms 30056 KB Output is correct
85 Correct 18 ms 30056 KB Output is correct
86 Correct 15 ms 30056 KB Output is correct
87 Correct 17 ms 30056 KB Output is correct
88 Correct 13 ms 30056 KB Output is correct
89 Correct 13 ms 30056 KB Output is correct
90 Correct 14 ms 30056 KB Output is correct
91 Correct 16 ms 30056 KB Output is correct
92 Correct 16 ms 30056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9852 KB Output is correct
2 Correct 12 ms 9852 KB Output is correct
3 Correct 11 ms 9852 KB Output is correct
4 Correct 11 ms 9852 KB Output is correct
5 Correct 16 ms 9896 KB Output is correct
6 Correct 12 ms 9896 KB Output is correct
7 Correct 14 ms 9896 KB Output is correct
8 Correct 12 ms 9896 KB Output is correct
9 Correct 14 ms 10132 KB Output is correct
10 Correct 12 ms 10132 KB Output is correct
11 Correct 13 ms 10132 KB Output is correct
12 Correct 13 ms 10132 KB Output is correct
13 Correct 18 ms 10132 KB Output is correct
14 Correct 14 ms 10132 KB Output is correct
15 Correct 15 ms 10132 KB Output is correct
16 Correct 11 ms 10132 KB Output is correct
17 Correct 11 ms 10132 KB Output is correct
18 Correct 13 ms 10132 KB Output is correct
19 Correct 12 ms 10132 KB Output is correct
20 Correct 11 ms 10132 KB Output is correct
21 Correct 12 ms 10132 KB Output is correct
22 Correct 12 ms 10132 KB Output is correct
23 Correct 13 ms 10132 KB Output is correct
24 Correct 12 ms 10132 KB Output is correct
25 Correct 12 ms 10132 KB Output is correct
26 Correct 14 ms 10132 KB Output is correct
27 Correct 12 ms 10132 KB Output is correct
28 Correct 14 ms 10132 KB Output is correct
29 Correct 13 ms 10132 KB Output is correct
30 Correct 12 ms 10132 KB Output is correct
31 Correct 13 ms 10132 KB Output is correct
32 Correct 12 ms 10132 KB Output is correct
33 Correct 12 ms 10132 KB Output is correct
34 Correct 13 ms 10156 KB Output is correct
35 Correct 13 ms 10156 KB Output is correct
36 Correct 10 ms 10156 KB Output is correct
37 Correct 11 ms 10156 KB Output is correct
38 Correct 11 ms 10156 KB Output is correct
39 Correct 12 ms 10156 KB Output is correct
40 Correct 12 ms 10156 KB Output is correct
41 Correct 12 ms 10240 KB Output is correct
42 Correct 14 ms 10260 KB Output is correct
43 Correct 14 ms 10260 KB Output is correct
44 Correct 11 ms 10300 KB Output is correct
45 Correct 14 ms 10300 KB Output is correct
46 Correct 10 ms 10300 KB Output is correct
47 Correct 12 ms 10300 KB Output is correct
48 Correct 11 ms 10300 KB Output is correct
49 Correct 13 ms 10300 KB Output is correct
50 Correct 12 ms 10300 KB Output is correct
51 Correct 12 ms 10376 KB Output is correct
52 Correct 13 ms 10380 KB Output is correct
53 Correct 11 ms 10380 KB Output is correct
54 Correct 12 ms 10380 KB Output is correct
55 Correct 12 ms 10380 KB Output is correct
56 Correct 13 ms 10380 KB Output is correct
57 Correct 14 ms 10380 KB Output is correct
58 Correct 12 ms 10380 KB Output is correct
59 Correct 12 ms 10380 KB Output is correct
60 Correct 11 ms 10380 KB Output is correct
61 Correct 11 ms 10380 KB Output is correct
62 Correct 11 ms 10380 KB Output is correct
63 Correct 12 ms 10380 KB Output is correct
64 Correct 9 ms 10380 KB Output is correct
65 Correct 15 ms 10380 KB Output is correct
66 Correct 168 ms 28860 KB Output is correct
67 Correct 164 ms 30000 KB Output is correct
68 Execution timed out 1069 ms 30056 KB Time limit exceeded
69 Halted 0 ms 0 KB -