Submission #62615

# Submission time Handle Problem Language Result Execution time Memory
62615 2018-07-29T11:52:56 Z SpaimaCarpatilor Simurgh (IOI17_simurgh) C++17
51 / 100
215 ms 8656 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;

int N, M, id[509][509], x[130009], y[130009], ans[130009], q[130009];
bool traversed[130009];
bool anyEdge[509][509];
vector < int > v[509];

namespace edgesFinder
{
    bool ap[509];
    vector < int > starterPack, currComp;
    void dfs (int nod)
    {
        ap[nod] = 1, currComp.push_back (nod);
        for (auto it : v[nod])
            if (ap[it] == 0)
                starterPack.push_back (id[nod][it]), dfs (it);
    }

    void findEdges (int nod)
    {
        memset (ap, 0, sizeof (ap)), ap[nod] = 1;
        starterPack.clear ();
        vector < vector < int > > currEdges;
        vector < int > representative;
        for (int i=0; i<N; i++)
            if (ap[i] == 0)
            {
                currComp.clear ();
                dfs (i);
                vector < int > curr;
                for (auto j : currComp)
                    if (anyEdge[nod][j])
                        curr.push_back (id[nod][j]);
                currEdges.push_back (curr);
                representative.push_back (curr[0]);
            }
        for (int i=0; i<currEdges.size (); i++)
            if (currEdges[i].size () == 1)
                traversed[representative[i]] = 1, ans[representative[i]] = 1;
            else
            {
                vector < int > curr = starterPack;
                for (int j=0; j<currEdges.size (); j++)
                    if (j != i)
                        curr.push_back (representative[j]);
                int maxi = -1;
                bool anyOther = 0;
                for (auto j : currEdges[i])
                    if (!traversed[j])
                    {
                        curr.push_back (j);
                        q[j] = count_common_roads (curr);
                        if (q[j] > maxi)
                            maxi = q[j];
                        curr.pop_back ();
                    }
                    else
                    if (traversed[j] == 1 && ans[j] == 1 && !anyOther)
                    {
                        anyOther = 1;
                        curr.push_back (j);
                        int currQ = count_common_roads (curr);
                        if (currQ > maxi)
                            maxi = currQ;
                        curr.pop_back ();
                    }
                for (auto j : currEdges[i])
                    if (!traversed[j])
                    {
                        traversed[j] = 1;
                        ans[j] = (maxi == q[j]);
                    }
            }
    }
};

vector < int > find_roads (int nn, vector < int > uu, vector < int > vv)
{
    N = nn, M = uu.size ();
    for (int i=0; i<M; i++)
        anyEdge[uu[i]][vv[i]] = anyEdge[vv[i]][uu[i]] = 1,
        id[uu[i]][vv[i]] = id[vv[i]][uu[i]] = i,
        x[i + 1] = uu[i], y[i + 1] = vv[i],
        v[x[i + 1]].push_back (y[i + 1]),
        v[y[i + 1]].push_back (x[i + 1]);
    //bool isNew[100009];
    //memset (isNew, 0, sizeof (isNew));
    for (int i=0; i<N; i++)
    {
        edgesFinder::findEdges (i);
        /*printf ("added %d's edges\n", i);
        for (int j=0; j<M; j++)
            if (traversed[j] == 1 && isNew[j] == 0)
            {
                printf ("%d -> %d\n", j, ans[j]);
                isNew[j] = 1;
            }*/
    }
    vector < int > finalAns;
    for (int i=0; i<M; i++)
        if (ans[i])
            finalAns.push_back (i);
    return finalAns;
}

Compilation message

simurgh.cpp: In function 'void edgesFinder::findEdges(int)':
simurgh.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0; i<currEdges.size (); i++)
                       ~^~~~~~~~~~~~~~~~~~
simurgh.cpp:46:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j=0; j<currEdges.size (); j++)
                               ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB correct
2 Correct 4 ms 376 KB correct
3 Correct 2 ms 420 KB correct
4 Correct 3 ms 472 KB correct
5 Correct 2 ms 476 KB correct
6 Correct 2 ms 680 KB correct
7 Correct 3 ms 680 KB correct
8 Correct 3 ms 680 KB correct
9 Correct 4 ms 688 KB correct
10 Correct 3 ms 764 KB correct
11 Correct 3 ms 764 KB correct
12 Correct 3 ms 764 KB correct
13 Correct 3 ms 764 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB correct
2 Correct 4 ms 376 KB correct
3 Correct 2 ms 420 KB correct
4 Correct 3 ms 472 KB correct
5 Correct 2 ms 476 KB correct
6 Correct 2 ms 680 KB correct
7 Correct 3 ms 680 KB correct
8 Correct 3 ms 680 KB correct
9 Correct 4 ms 688 KB correct
10 Correct 3 ms 764 KB correct
11 Correct 3 ms 764 KB correct
12 Correct 3 ms 764 KB correct
13 Correct 3 ms 764 KB correct
14 Correct 6 ms 988 KB correct
15 Correct 6 ms 992 KB correct
16 Correct 6 ms 992 KB correct
17 Correct 6 ms 992 KB correct
18 Correct 5 ms 992 KB correct
19 Correct 5 ms 992 KB correct
20 Correct 5 ms 992 KB correct
21 Correct 4 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 6 ms 992 KB correct
24 Correct 4 ms 1008 KB correct
25 Correct 3 ms 1012 KB correct
26 Correct 6 ms 1016 KB correct
27 Correct 4 ms 1020 KB correct
28 Correct 4 ms 1024 KB correct
29 Correct 5 ms 1028 KB correct
30 Correct 3 ms 1096 KB correct
31 Correct 5 ms 1096 KB correct
32 Correct 4 ms 1096 KB correct
33 Correct 5 ms 1216 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB correct
2 Correct 4 ms 376 KB correct
3 Correct 2 ms 420 KB correct
4 Correct 3 ms 472 KB correct
5 Correct 2 ms 476 KB correct
6 Correct 2 ms 680 KB correct
7 Correct 3 ms 680 KB correct
8 Correct 3 ms 680 KB correct
9 Correct 4 ms 688 KB correct
10 Correct 3 ms 764 KB correct
11 Correct 3 ms 764 KB correct
12 Correct 3 ms 764 KB correct
13 Correct 3 ms 764 KB correct
14 Correct 6 ms 988 KB correct
15 Correct 6 ms 992 KB correct
16 Correct 6 ms 992 KB correct
17 Correct 6 ms 992 KB correct
18 Correct 5 ms 992 KB correct
19 Correct 5 ms 992 KB correct
20 Correct 5 ms 992 KB correct
21 Correct 4 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 6 ms 992 KB correct
24 Correct 4 ms 1008 KB correct
25 Correct 3 ms 1012 KB correct
26 Correct 6 ms 1016 KB correct
27 Correct 4 ms 1020 KB correct
28 Correct 4 ms 1024 KB correct
29 Correct 5 ms 1028 KB correct
30 Correct 3 ms 1096 KB correct
31 Correct 5 ms 1096 KB correct
32 Correct 4 ms 1096 KB correct
33 Correct 5 ms 1216 KB correct
34 Correct 157 ms 2860 KB correct
35 Correct 150 ms 3076 KB correct
36 Correct 96 ms 3104 KB correct
37 Correct 13 ms 3104 KB correct
38 Correct 135 ms 3524 KB correct
39 Correct 132 ms 3600 KB correct
40 Correct 99 ms 3600 KB correct
41 Correct 215 ms 4036 KB correct
42 Correct 156 ms 4232 KB correct
43 Correct 92 ms 4232 KB correct
44 Correct 68 ms 4232 KB correct
45 Correct 99 ms 4232 KB correct
46 Correct 59 ms 4232 KB correct
47 Correct 33 ms 4232 KB correct
48 Correct 7 ms 4232 KB correct
49 Correct 13 ms 4232 KB correct
50 Correct 29 ms 4232 KB correct
51 Correct 75 ms 4252 KB correct
52 Correct 63 ms 4252 KB correct
53 Correct 52 ms 4312 KB correct
54 Correct 73 ms 4668 KB correct
55 Correct 74 ms 4668 KB correct
56 Correct 69 ms 4728 KB correct
57 Correct 87 ms 4820 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4820 KB correct
2 Correct 3 ms 4820 KB correct
3 Incorrect 112 ms 8656 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB correct
2 Correct 4 ms 376 KB correct
3 Correct 2 ms 420 KB correct
4 Correct 3 ms 472 KB correct
5 Correct 2 ms 476 KB correct
6 Correct 2 ms 680 KB correct
7 Correct 3 ms 680 KB correct
8 Correct 3 ms 680 KB correct
9 Correct 4 ms 688 KB correct
10 Correct 3 ms 764 KB correct
11 Correct 3 ms 764 KB correct
12 Correct 3 ms 764 KB correct
13 Correct 3 ms 764 KB correct
14 Correct 6 ms 988 KB correct
15 Correct 6 ms 992 KB correct
16 Correct 6 ms 992 KB correct
17 Correct 6 ms 992 KB correct
18 Correct 5 ms 992 KB correct
19 Correct 5 ms 992 KB correct
20 Correct 5 ms 992 KB correct
21 Correct 4 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 6 ms 992 KB correct
24 Correct 4 ms 1008 KB correct
25 Correct 3 ms 1012 KB correct
26 Correct 6 ms 1016 KB correct
27 Correct 4 ms 1020 KB correct
28 Correct 4 ms 1024 KB correct
29 Correct 5 ms 1028 KB correct
30 Correct 3 ms 1096 KB correct
31 Correct 5 ms 1096 KB correct
32 Correct 4 ms 1096 KB correct
33 Correct 5 ms 1216 KB correct
34 Correct 157 ms 2860 KB correct
35 Correct 150 ms 3076 KB correct
36 Correct 96 ms 3104 KB correct
37 Correct 13 ms 3104 KB correct
38 Correct 135 ms 3524 KB correct
39 Correct 132 ms 3600 KB correct
40 Correct 99 ms 3600 KB correct
41 Correct 215 ms 4036 KB correct
42 Correct 156 ms 4232 KB correct
43 Correct 92 ms 4232 KB correct
44 Correct 68 ms 4232 KB correct
45 Correct 99 ms 4232 KB correct
46 Correct 59 ms 4232 KB correct
47 Correct 33 ms 4232 KB correct
48 Correct 7 ms 4232 KB correct
49 Correct 13 ms 4232 KB correct
50 Correct 29 ms 4232 KB correct
51 Correct 75 ms 4252 KB correct
52 Correct 63 ms 4252 KB correct
53 Correct 52 ms 4312 KB correct
54 Correct 73 ms 4668 KB correct
55 Correct 74 ms 4668 KB correct
56 Correct 69 ms 4728 KB correct
57 Correct 87 ms 4820 KB correct
58 Correct 3 ms 4820 KB correct
59 Correct 3 ms 4820 KB correct
60 Incorrect 112 ms 8656 KB WA in grader: NO
61 Halted 0 ms 0 KB -