답안 #62638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62638 2018-07-29T15:06:00 Z SpaimaCarpatilor Simurgh (IOI17_simurgh) C++17
70 / 100
614 ms 9136 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], h[509];

namespace fixedSTfinder
{
    int ap[509], t[509], low[509], lev[509];
    bool ap2[509];
    void dfs (int nod)
    {
        ap[nod] = 2, low[nod] = nod;
        for (auto it : v[nod])
            if (ap[it] == 0)
                t[it] = nod, lev[it] = lev[nod] + 1,
                h[it].push_back (nod),
                h[nod].push_back (it),
                dfs (it);
            else
            if (ap[it] == 2 && t[nod] != it)
            {
                if (lev[it] < lev[low[nod]])
                    low[nod] = it;
            }
        ap[nod] = 1;
    }

    void findFixedST ()
    {
        t[0] = -1, dfs (0);
        for (int i=1; i<N; i++)
            if (low[i] != i)
            {
                int x = low[i], y = i;
                vector < int > currEdges, starterPack;
                memset (ap2, 0, sizeof (ap2));
                currEdges.push_back (id[x][y]);
                while (y != x)
                    currEdges.push_back (id[y][t[y]]),
                    ap2[y] = 1, y = t[y];
                for (int j=1; j<N; j++)
                    if (ap2[j] == 0)
                        starterPack.push_back (id[j][t[j]]);
                bool anyKnown = 0;
                int allS = 0, ma = 0, mi = N;
                for (int j=0; j<currEdges.size (); j++)
                {
                    vector < int > curr = starterPack;
                    for (int k=0; k<currEdges.size (); k++)
                        if (k != j)
                            curr.push_back (currEdges[k]);
                    if (traversed[currEdges[j]])
                    {
                        if (anyKnown == 0)
                        {
                            allS = ans[currEdges[j]] + count_common_roads (curr);
                            anyKnown = 1;
                        }
                        q[currEdges[j]] = allS - ans[currEdges[j]];
                    }
                    else q[currEdges[j]] = count_common_roads (curr);
                    mi = min (mi, q[currEdges[j]]);
                    ma = max (ma, q[currEdges[j]]);
                }
                if (mi == ma)
                {
                    for (auto e : currEdges)
                        ans[e] = 0;
                }
                else
                {
                    for (auto e : currEdges)
                        if (q[e] == mi)
                            ans[e] = 1;
                }
                for (auto e : currEdges)
                    traversed[e] = 1;
            }
        for (int i=1; i<N; i++)
            if (traversed[id[i][t[i]]] == 0)
                traversed[id[i][t[i]]] = 1,
                ans[id[i][t[i]]] = 1;///it's critical then
    }
}

namespace edgesFinderGivenFixedST
{
    bool ap[509];
    void dfs (int nod, int &currCost, vector < int > &curr)
    {
        ap[nod] = 1;
        for (auto it : h[nod])
            if (ap[it] == 0)
                curr.push_back (id[nod][it]),
                currCost += ans[id[nod][it]],
                dfs (it, currCost, curr);
    }

    void findEdges (int nod)
    {
        vector < int > possibleEdges;
        for (int i=0; i<N; i++)
            if (anyEdge[nod][i] && !traversed[id[nod][i]])
                possibleEdges.push_back (id[nod][i]),
                traversed[id[nod][i]] = 1;
        for (int l=0; l<possibleEdges.size (); l++)
        {
            int p = l, u = possibleEdges.size () - 1, ras = possibleEdges.size ();
            while (p <= u)
            {
                int mij = (p + u) >> 1, q = 0;
                vector < int > curr;
                memset (ap, 0, sizeof (ap)), ap[nod] = 1;
                for (int i=l; i<=mij; i++)
                {
                    int otherEnd = x[possibleEdges[i]] ^ y[possibleEdges[i]] ^ nod;
                    ap[otherEnd] = 1, curr.push_back (possibleEdges[i]);
                }
                dfs (nod, q, curr);
                for (int i=l; i<=mij; i++)
                {
                    int otherEnd = x[possibleEdges[i]] ^ y[possibleEdges[i]] ^ nod;
                    dfs (otherEnd, q, curr);
                }
                if (count_common_roads (curr) > q) ras = mij, u = mij - 1;
                else p = mij + 1;
            }
            if (ras == possibleEdges.size ()) break;
            ans[possibleEdges[ras]] = 1, l = ras;
        }
    }
}

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] = uu[i], y[i] = vv[i],
        v[x[i]].push_back (y[i]),
        v[y[i]].push_back (x[i]);
    /*if (N <= 240)
    {
        for (int i=0; i<N; i++)
            edgesFinder::findEdges (i);
    }
    else
    {*/
        //bool isNew[100009];
        //memset (isNew, 0, sizeof (isNew));
        //findFixedSTcompleteGraph ();
        fixedSTfinder::findFixedST ();
        /*printf ("initial ST:\n");
        for (int i=0; i<N; i++)
            for (auto j : h[i])
                if (j > i)
                    printf ("%d [%d, %d] -> %d\n", id[i][j], i, j, ans[id[i][j]]);*/
        for (int i=0; i<N; i++)
        {
            edgesFinderGivenFixedST::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 fixedSTfinder::findFixedST()':
simurgh.cpp:50:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j=0; j<currEdges.size (); j++)
                               ~^~~~~~~~~~~~~~~~~~
simurgh.cpp:53:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int k=0; k<currEdges.size (); k++)
                                   ~^~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'void edgesFinderGivenFixedST::findEdges(int)':
simurgh.cpp:110:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int l=0; l<possibleEdges.size (); l++)
                       ~^~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:132:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (ras == possibleEdges.size ()) break;
                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB correct
2 Correct 3 ms 492 KB correct
3 Correct 4 ms 492 KB correct
4 Correct 3 ms 568 KB correct
5 Correct 4 ms 624 KB correct
6 Correct 2 ms 624 KB correct
7 Correct 3 ms 624 KB correct
8 Correct 3 ms 700 KB correct
9 Correct 3 ms 700 KB correct
10 Correct 3 ms 700 KB correct
11 Correct 2 ms 700 KB correct
12 Correct 2 ms 700 KB correct
13 Correct 2 ms 700 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB correct
2 Correct 3 ms 492 KB correct
3 Correct 4 ms 492 KB correct
4 Correct 3 ms 568 KB correct
5 Correct 4 ms 624 KB correct
6 Correct 2 ms 624 KB correct
7 Correct 3 ms 624 KB correct
8 Correct 3 ms 700 KB correct
9 Correct 3 ms 700 KB correct
10 Correct 3 ms 700 KB correct
11 Correct 2 ms 700 KB correct
12 Correct 2 ms 700 KB correct
13 Correct 2 ms 700 KB correct
14 Correct 4 ms 916 KB correct
15 Correct 8 ms 916 KB correct
16 Correct 7 ms 936 KB correct
17 Correct 5 ms 936 KB correct
18 Correct 4 ms 936 KB correct
19 Correct 6 ms 936 KB correct
20 Correct 6 ms 936 KB correct
21 Correct 6 ms 976 KB correct
22 Correct 4 ms 976 KB correct
23 Correct 5 ms 976 KB correct
24 Correct 5 ms 976 KB correct
25 Correct 3 ms 976 KB correct
26 Correct 5 ms 976 KB correct
27 Correct 5 ms 976 KB correct
28 Correct 4 ms 976 KB correct
29 Correct 4 ms 976 KB correct
30 Correct 5 ms 976 KB correct
31 Correct 6 ms 976 KB correct
32 Correct 5 ms 976 KB correct
33 Correct 4 ms 976 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB correct
2 Correct 3 ms 492 KB correct
3 Correct 4 ms 492 KB correct
4 Correct 3 ms 568 KB correct
5 Correct 4 ms 624 KB correct
6 Correct 2 ms 624 KB correct
7 Correct 3 ms 624 KB correct
8 Correct 3 ms 700 KB correct
9 Correct 3 ms 700 KB correct
10 Correct 3 ms 700 KB correct
11 Correct 2 ms 700 KB correct
12 Correct 2 ms 700 KB correct
13 Correct 2 ms 700 KB correct
14 Correct 4 ms 916 KB correct
15 Correct 8 ms 916 KB correct
16 Correct 7 ms 936 KB correct
17 Correct 5 ms 936 KB correct
18 Correct 4 ms 936 KB correct
19 Correct 6 ms 936 KB correct
20 Correct 6 ms 936 KB correct
21 Correct 6 ms 976 KB correct
22 Correct 4 ms 976 KB correct
23 Correct 5 ms 976 KB correct
24 Correct 5 ms 976 KB correct
25 Correct 3 ms 976 KB correct
26 Correct 5 ms 976 KB correct
27 Correct 5 ms 976 KB correct
28 Correct 4 ms 976 KB correct
29 Correct 4 ms 976 KB correct
30 Correct 5 ms 976 KB correct
31 Correct 6 ms 976 KB correct
32 Correct 5 ms 976 KB correct
33 Correct 4 ms 976 KB correct
34 Correct 74 ms 2840 KB correct
35 Correct 83 ms 2912 KB correct
36 Correct 70 ms 2912 KB correct
37 Correct 31 ms 2912 KB correct
38 Correct 83 ms 3384 KB correct
39 Correct 106 ms 3456 KB correct
40 Correct 76 ms 3456 KB correct
41 Correct 102 ms 3900 KB correct
42 Correct 82 ms 4092 KB correct
43 Correct 48 ms 4092 KB correct
44 Correct 53 ms 4092 KB correct
45 Correct 42 ms 4092 KB correct
46 Correct 37 ms 4092 KB correct
47 Correct 32 ms 4092 KB correct
48 Correct 8 ms 4092 KB correct
49 Correct 19 ms 4092 KB correct
50 Correct 24 ms 4092 KB correct
51 Correct 41 ms 4092 KB correct
52 Correct 36 ms 4092 KB correct
53 Correct 35 ms 4092 KB correct
54 Correct 43 ms 4092 KB correct
55 Correct 64 ms 4092 KB correct
56 Correct 57 ms 4092 KB correct
57 Correct 80 ms 4092 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4092 KB correct
2 Correct 4 ms 4092 KB correct
3 Correct 348 ms 7056 KB correct
4 Correct 614 ms 9080 KB correct
5 Correct 469 ms 9080 KB correct
6 Correct 499 ms 9092 KB correct
7 Correct 485 ms 9092 KB correct
8 Correct 439 ms 9092 KB correct
9 Correct 588 ms 9136 KB correct
10 Correct 536 ms 9136 KB correct
11 Correct 465 ms 9136 KB correct
12 Correct 436 ms 9136 KB correct
13 Correct 2 ms 9136 KB correct
14 Correct 428 ms 9136 KB correct
15 Correct 590 ms 9136 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB correct
2 Correct 3 ms 492 KB correct
3 Correct 4 ms 492 KB correct
4 Correct 3 ms 568 KB correct
5 Correct 4 ms 624 KB correct
6 Correct 2 ms 624 KB correct
7 Correct 3 ms 624 KB correct
8 Correct 3 ms 700 KB correct
9 Correct 3 ms 700 KB correct
10 Correct 3 ms 700 KB correct
11 Correct 2 ms 700 KB correct
12 Correct 2 ms 700 KB correct
13 Correct 2 ms 700 KB correct
14 Correct 4 ms 916 KB correct
15 Correct 8 ms 916 KB correct
16 Correct 7 ms 936 KB correct
17 Correct 5 ms 936 KB correct
18 Correct 4 ms 936 KB correct
19 Correct 6 ms 936 KB correct
20 Correct 6 ms 936 KB correct
21 Correct 6 ms 976 KB correct
22 Correct 4 ms 976 KB correct
23 Correct 5 ms 976 KB correct
24 Correct 5 ms 976 KB correct
25 Correct 3 ms 976 KB correct
26 Correct 5 ms 976 KB correct
27 Correct 5 ms 976 KB correct
28 Correct 4 ms 976 KB correct
29 Correct 4 ms 976 KB correct
30 Correct 5 ms 976 KB correct
31 Correct 6 ms 976 KB correct
32 Correct 5 ms 976 KB correct
33 Correct 4 ms 976 KB correct
34 Correct 74 ms 2840 KB correct
35 Correct 83 ms 2912 KB correct
36 Correct 70 ms 2912 KB correct
37 Correct 31 ms 2912 KB correct
38 Correct 83 ms 3384 KB correct
39 Correct 106 ms 3456 KB correct
40 Correct 76 ms 3456 KB correct
41 Correct 102 ms 3900 KB correct
42 Correct 82 ms 4092 KB correct
43 Correct 48 ms 4092 KB correct
44 Correct 53 ms 4092 KB correct
45 Correct 42 ms 4092 KB correct
46 Correct 37 ms 4092 KB correct
47 Correct 32 ms 4092 KB correct
48 Correct 8 ms 4092 KB correct
49 Correct 19 ms 4092 KB correct
50 Correct 24 ms 4092 KB correct
51 Correct 41 ms 4092 KB correct
52 Correct 36 ms 4092 KB correct
53 Correct 35 ms 4092 KB correct
54 Correct 43 ms 4092 KB correct
55 Correct 64 ms 4092 KB correct
56 Correct 57 ms 4092 KB correct
57 Correct 80 ms 4092 KB correct
58 Correct 3 ms 4092 KB correct
59 Correct 4 ms 4092 KB correct
60 Correct 348 ms 7056 KB correct
61 Correct 614 ms 9080 KB correct
62 Correct 469 ms 9080 KB correct
63 Correct 499 ms 9092 KB correct
64 Correct 485 ms 9092 KB correct
65 Correct 439 ms 9092 KB correct
66 Correct 588 ms 9136 KB correct
67 Correct 536 ms 9136 KB correct
68 Correct 465 ms 9136 KB correct
69 Correct 436 ms 9136 KB correct
70 Correct 2 ms 9136 KB correct
71 Correct 428 ms 9136 KB correct
72 Correct 590 ms 9136 KB correct
73 Correct 3 ms 9136 KB correct
74 Incorrect 446 ms 9136 KB WA in grader: NO
75 Halted 0 ms 0 KB -