Submission #233305

# Submission time Handle Problem Language Result Execution time Memory
233305 2020-05-20T08:56:23 Z Ruxandra985 Duathlon (APIO18_duathlon) C++14
49 / 100
166 ms 37740 KB
#include <bits/stdc++.h>
#define DIMN 100005
#define DIMM 200005
using namespace std;
long long low[DIMN] , bicnx , lvl[DIMN] , taken[DIMN] , f[DIMN] , under[DIMN] , two[DIMN];
stack <long long> st;
vector <long long> v[DIMN] , w[2 * DIMN];
set <long long> sol[DIMN];
long long x , n , val;
void dfs_bic (long long nod,long long tt){
    long long i,vecin;
    low[nod]=lvl[nod];
    st.push(nod);
    for (i=0;i<v[nod].size();i++){
        vecin=v[nod][i];
        if (vecin==tt)
            continue;
        if (lvl[vecin]==0){
            lvl[vecin]=1+lvl[nod];
            dfs_bic(vecin,nod);
            low[nod]=min(low[nod],low[vecin]);
            if (low[vecin]>=lvl[nod]){ /// nod e un nod critic
                bicnx++;
                do{
                    x=st.top();
                    taken[x]++;
                    st.pop();
                    sol[bicnx].insert(x);
                }
                while (x!=vecin);
                sol[bicnx].insert(nod);
                taken[nod]++;
                /// am scos din stiva muchiile care sunt in subarborele nod->vecin
            }
        }
        else low[nod]=min(low[nod],lvl[vecin]);
    }
}


void precalc (int nod , int tt){

    int i , vecin;

    if (nod <= n){ /// nod

        under[nod] = 1;

    }
    else under[nod] = 0;

    for (i = 0 ; i < w[nod].size() ; i++){
        vecin = w[nod][i];
        if (vecin != tt){

            precalc (vecin , nod);

            under[nod] += under[vecin];

            if (nod > n){
                two[nod] += under[vecin] * (under[vecin] - 1);
            }


        }
    }

}

void dfs (int root , int nod , int tt){
    int i , vecin;

    f[nod] = 1;

    for (i = 0 ; i < w[nod].size() ; i++){
        vecin = w[nod][i];
        if (vecin != tt){

            dfs (root , vecin , nod);

        }
    }

    //if (nod == 5)
      //  printf ("a");

    if (nod <= n){ /// nod

        for (i = 0 ; i < w[nod].size() ; i++){
            vecin = w[nod][i];
            if (vecin != tt){

                val -= two[vecin];

                /// din vecin -> nod -> din vecin

            }
        }

    }
    else { /// componenta

        for (i = 0 ; i < w[nod].size() ; i++){
            vecin = w[nod][i];
            if (vecin != tt){

                val -= two[nod] - under[vecin] * (under[vecin] - 1) + (under[root] - under[nod]) * (under[root] - under[nod] - 1);

            }
        }

    }


}

int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    long long m , i , x , y , nod;
    fscanf (fin,"%lld%lld",&n,&m);
    for (i=1;i<=m;i++){
        fscanf (fin,"%lld%lld",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }

    for (i = 1 ; i <= n ; i++){
        if (!lvl[i]){

            lvl[i] = 1;
            dfs_bic (i , 0);

        }

    }

    for (i = 1 ; i <= bicnx ; i++){

        for (set <long long> :: iterator it = sol[i].begin() ; it != sol[i].end() ; it++){

            nod = *it;

            w[nod].push_back(n + i);
            w[n + i].push_back(nod);

            //fprintf (fout,"%lld %lld\n" , nod , n + i);

        }

    }

    for (i = 1 ; i <= n ; i++){
        if (!f[i]){
            precalc(i , 0);
            dfs(i , i , 0);
            val += under[i] * (under[i] - 1) * (under[i] - 2);
        }
    }

    fprintf (fout,"%lld",val);

    return 0;
}

Compilation message

count_triplets.cpp: In function 'void dfs_bic(long long int, long long int)':
count_triplets.cpp:14:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
count_triplets.cpp: In function 'void precalc(int, int)':
count_triplets.cpp:52:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0 ; i < w[nod].size() ; i++){
                  ~~^~~~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs(int, int, int)':
count_triplets.cpp:75:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0 ; i < w[nod].size() ; i++){
                  ~~^~~~~~~~~~~~~~~
count_triplets.cpp:89:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0 ; i < w[nod].size() ; i++){
                      ~~^~~~~~~~~~~~~~~
count_triplets.cpp:103:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0 ; i < w[nod].size() ; i++){
                      ~~^~~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:122:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%lld%lld",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:124:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld%lld",&x,&y);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 11 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 11 ms 12032 KB Output is correct
7 Correct 12 ms 12160 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 11 ms 12160 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12160 KB Output is correct
22 Correct 11 ms 12032 KB Output is correct
23 Correct 12 ms 12032 KB Output is correct
24 Correct 11 ms 12032 KB Output is correct
25 Correct 13 ms 12032 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 11 ms 12032 KB Output is correct
29 Correct 11 ms 12032 KB Output is correct
30 Correct 11 ms 12032 KB Output is correct
31 Correct 11 ms 12032 KB Output is correct
32 Correct 11 ms 12032 KB Output is correct
33 Correct 11 ms 12160 KB Output is correct
34 Correct 11 ms 12032 KB Output is correct
35 Correct 11 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 11 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 11 ms 12032 KB Output is correct
7 Correct 12 ms 12160 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 11 ms 12160 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12160 KB Output is correct
22 Correct 11 ms 12032 KB Output is correct
23 Correct 12 ms 12032 KB Output is correct
24 Correct 11 ms 12032 KB Output is correct
25 Correct 13 ms 12032 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 11 ms 12032 KB Output is correct
29 Correct 11 ms 12032 KB Output is correct
30 Correct 11 ms 12032 KB Output is correct
31 Correct 11 ms 12032 KB Output is correct
32 Correct 11 ms 12032 KB Output is correct
33 Correct 11 ms 12160 KB Output is correct
34 Correct 11 ms 12032 KB Output is correct
35 Correct 11 ms 12032 KB Output is correct
36 Correct 12 ms 12160 KB Output is correct
37 Correct 13 ms 12032 KB Output is correct
38 Correct 11 ms 12032 KB Output is correct
39 Correct 11 ms 12032 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 11 ms 12032 KB Output is correct
42 Correct 12 ms 12160 KB Output is correct
43 Correct 12 ms 12160 KB Output is correct
44 Correct 11 ms 12032 KB Output is correct
45 Correct 11 ms 12160 KB Output is correct
46 Correct 12 ms 12032 KB Output is correct
47 Correct 11 ms 12160 KB Output is correct
48 Correct 11 ms 12160 KB Output is correct
49 Correct 11 ms 12032 KB Output is correct
50 Correct 12 ms 12032 KB Output is correct
51 Correct 11 ms 12160 KB Output is correct
52 Correct 12 ms 12160 KB Output is correct
53 Correct 12 ms 12160 KB Output is correct
54 Correct 11 ms 12040 KB Output is correct
55 Correct 11 ms 12032 KB Output is correct
56 Correct 13 ms 12032 KB Output is correct
57 Correct 11 ms 12032 KB Output is correct
58 Correct 11 ms 12032 KB Output is correct
59 Correct 12 ms 12160 KB Output is correct
60 Correct 11 ms 12160 KB Output is correct
61 Correct 11 ms 12032 KB Output is correct
62 Correct 12 ms 12160 KB Output is correct
63 Correct 11 ms 12160 KB Output is correct
64 Correct 11 ms 12160 KB Output is correct
65 Correct 11 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 35192 KB Output is correct
2 Correct 144 ms 35180 KB Output is correct
3 Incorrect 166 ms 37740 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12288 KB Output is correct
2 Correct 12 ms 12416 KB Output is correct
3 Correct 12 ms 12416 KB Output is correct
4 Correct 12 ms 12416 KB Output is correct
5 Correct 12 ms 12416 KB Output is correct
6 Correct 13 ms 12416 KB Output is correct
7 Correct 13 ms 12416 KB Output is correct
8 Correct 12 ms 12416 KB Output is correct
9 Correct 13 ms 12416 KB Output is correct
10 Correct 13 ms 12288 KB Output is correct
11 Correct 12 ms 12416 KB Output is correct
12 Correct 12 ms 12288 KB Output is correct
13 Correct 13 ms 12416 KB Output is correct
14 Correct 13 ms 12288 KB Output is correct
15 Correct 13 ms 12288 KB Output is correct
16 Correct 12 ms 12288 KB Output is correct
17 Correct 12 ms 12416 KB Output is correct
18 Correct 12 ms 12416 KB Output is correct
19 Correct 12 ms 12416 KB Output is correct
20 Correct 12 ms 12416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 37240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12416 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 12 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 12 ms 12288 KB Output is correct
7 Correct 12 ms 12288 KB Output is correct
8 Correct 12 ms 12288 KB Output is correct
9 Correct 12 ms 12288 KB Output is correct
10 Correct 12 ms 12288 KB Output is correct
11 Correct 12 ms 12288 KB Output is correct
12 Correct 12 ms 12416 KB Output is correct
13 Correct 12 ms 12416 KB Output is correct
14 Correct 12 ms 12416 KB Output is correct
15 Correct 14 ms 12416 KB Output is correct
16 Correct 12 ms 12288 KB Output is correct
17 Correct 12 ms 12288 KB Output is correct
18 Correct 12 ms 12288 KB Output is correct
19 Correct 13 ms 12288 KB Output is correct
20 Correct 13 ms 12288 KB Output is correct
21 Correct 12 ms 12288 KB Output is correct
22 Correct 12 ms 12416 KB Output is correct
23 Correct 12 ms 12288 KB Output is correct
24 Correct 18 ms 12288 KB Output is correct
25 Correct 11 ms 12160 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 157 ms 37240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 11 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 11 ms 12032 KB Output is correct
7 Correct 12 ms 12160 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 11 ms 12160 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12160 KB Output is correct
22 Correct 11 ms 12032 KB Output is correct
23 Correct 12 ms 12032 KB Output is correct
24 Correct 11 ms 12032 KB Output is correct
25 Correct 13 ms 12032 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 11 ms 12032 KB Output is correct
29 Correct 11 ms 12032 KB Output is correct
30 Correct 11 ms 12032 KB Output is correct
31 Correct 11 ms 12032 KB Output is correct
32 Correct 11 ms 12032 KB Output is correct
33 Correct 11 ms 12160 KB Output is correct
34 Correct 11 ms 12032 KB Output is correct
35 Correct 11 ms 12032 KB Output is correct
36 Correct 12 ms 12160 KB Output is correct
37 Correct 13 ms 12032 KB Output is correct
38 Correct 11 ms 12032 KB Output is correct
39 Correct 11 ms 12032 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 11 ms 12032 KB Output is correct
42 Correct 12 ms 12160 KB Output is correct
43 Correct 12 ms 12160 KB Output is correct
44 Correct 11 ms 12032 KB Output is correct
45 Correct 11 ms 12160 KB Output is correct
46 Correct 12 ms 12032 KB Output is correct
47 Correct 11 ms 12160 KB Output is correct
48 Correct 11 ms 12160 KB Output is correct
49 Correct 11 ms 12032 KB Output is correct
50 Correct 12 ms 12032 KB Output is correct
51 Correct 11 ms 12160 KB Output is correct
52 Correct 12 ms 12160 KB Output is correct
53 Correct 12 ms 12160 KB Output is correct
54 Correct 11 ms 12040 KB Output is correct
55 Correct 11 ms 12032 KB Output is correct
56 Correct 13 ms 12032 KB Output is correct
57 Correct 11 ms 12032 KB Output is correct
58 Correct 11 ms 12032 KB Output is correct
59 Correct 12 ms 12160 KB Output is correct
60 Correct 11 ms 12160 KB Output is correct
61 Correct 11 ms 12032 KB Output is correct
62 Correct 12 ms 12160 KB Output is correct
63 Correct 11 ms 12160 KB Output is correct
64 Correct 11 ms 12160 KB Output is correct
65 Correct 11 ms 12032 KB Output is correct
66 Correct 12 ms 12160 KB Output is correct
67 Correct 12 ms 12288 KB Output is correct
68 Correct 13 ms 12340 KB Output is correct
69 Correct 15 ms 12288 KB Output is correct
70 Correct 14 ms 12288 KB Output is correct
71 Correct 13 ms 12288 KB Output is correct
72 Correct 12 ms 12288 KB Output is correct
73 Correct 12 ms 12288 KB Output is correct
74 Correct 12 ms 12288 KB Output is correct
75 Correct 13 ms 12288 KB Output is correct
76 Correct 11 ms 12160 KB Output is correct
77 Correct 13 ms 12288 KB Output is correct
78 Correct 12 ms 12288 KB Output is correct
79 Correct 12 ms 12288 KB Output is correct
80 Correct 12 ms 12288 KB Output is correct
81 Correct 12 ms 12288 KB Output is correct
82 Correct 14 ms 12288 KB Output is correct
83 Correct 12 ms 12288 KB Output is correct
84 Correct 12 ms 12288 KB Output is correct
85 Correct 13 ms 12288 KB Output is correct
86 Correct 13 ms 12288 KB Output is correct
87 Correct 12 ms 12288 KB Output is correct
88 Correct 13 ms 12288 KB Output is correct
89 Correct 12 ms 12288 KB Output is correct
90 Correct 12 ms 12288 KB Output is correct
91 Correct 12 ms 12288 KB Output is correct
92 Correct 13 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 11 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 11 ms 12032 KB Output is correct
7 Correct 12 ms 12160 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 11 ms 12160 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12160 KB Output is correct
22 Correct 11 ms 12032 KB Output is correct
23 Correct 12 ms 12032 KB Output is correct
24 Correct 11 ms 12032 KB Output is correct
25 Correct 13 ms 12032 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 11 ms 12032 KB Output is correct
29 Correct 11 ms 12032 KB Output is correct
30 Correct 11 ms 12032 KB Output is correct
31 Correct 11 ms 12032 KB Output is correct
32 Correct 11 ms 12032 KB Output is correct
33 Correct 11 ms 12160 KB Output is correct
34 Correct 11 ms 12032 KB Output is correct
35 Correct 11 ms 12032 KB Output is correct
36 Correct 12 ms 12160 KB Output is correct
37 Correct 13 ms 12032 KB Output is correct
38 Correct 11 ms 12032 KB Output is correct
39 Correct 11 ms 12032 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 11 ms 12032 KB Output is correct
42 Correct 12 ms 12160 KB Output is correct
43 Correct 12 ms 12160 KB Output is correct
44 Correct 11 ms 12032 KB Output is correct
45 Correct 11 ms 12160 KB Output is correct
46 Correct 12 ms 12032 KB Output is correct
47 Correct 11 ms 12160 KB Output is correct
48 Correct 11 ms 12160 KB Output is correct
49 Correct 11 ms 12032 KB Output is correct
50 Correct 12 ms 12032 KB Output is correct
51 Correct 11 ms 12160 KB Output is correct
52 Correct 12 ms 12160 KB Output is correct
53 Correct 12 ms 12160 KB Output is correct
54 Correct 11 ms 12040 KB Output is correct
55 Correct 11 ms 12032 KB Output is correct
56 Correct 13 ms 12032 KB Output is correct
57 Correct 11 ms 12032 KB Output is correct
58 Correct 11 ms 12032 KB Output is correct
59 Correct 12 ms 12160 KB Output is correct
60 Correct 11 ms 12160 KB Output is correct
61 Correct 11 ms 12032 KB Output is correct
62 Correct 12 ms 12160 KB Output is correct
63 Correct 11 ms 12160 KB Output is correct
64 Correct 11 ms 12160 KB Output is correct
65 Correct 11 ms 12032 KB Output is correct
66 Correct 142 ms 35192 KB Output is correct
67 Correct 144 ms 35180 KB Output is correct
68 Incorrect 166 ms 37740 KB Output isn't correct
69 Halted 0 ms 0 KB -