Submission #397156

# Submission time Handle Problem Language Result Execution time Memory
397156 2021-05-01T15:16:05 Z idk321 Simurgh (IOI17_simurgh) C++11
51 / 100
300 ms 10608 KB
#include "simurgh.h"


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 300000;
const int M = 300000;
vector<array<int, 2>> adj[N];
int n;
int m;

int in[N];
int up[N];
int timer;
bool done[M];
bool inRes[M];

void bridges(int node, int par, int pEdge)
{
    in[node] = ++timer;
    up[node] = in[node];

    for (auto next : adj[node])
    {
        if (next[0] == par) continue;
        if (in[next[0]] == 0)
        {
            bridges(next[0], node, next[1]);
            up[node] = min(up[node], up[next[0]]);
        } else
        {
            up[node] = min(up[node], up[next[0]]);
        }
    }

    if (par != -1 && up[node] == in[node])
    {
        done[pEdge] = true;
    }
}

int p[N];

int getRoot(int a)
{
    if (p[a] == a) return a;
    p[a] = getRoot(p[a]);
    return p[a];
}

void join(int a, int b)
{
    a = getRoot(a);
    b = getRoot(b);
    p[b] = a;
}


bool isBad[M];
int resAt[M];
bool vis[M];

std::vector<int> find_roads(int XD, std::vector<int> u, std::vector<int> v) {
    n = XD;
    m = u.size();
    for (int i = 0; i < m; i++)
    {
        adj[u[i]].push_back({v[i], i});
        adj[v[i]].push_back({u[i], i});
    }

    bridges(0, -1, -1);

    vector<int> res;
    for (int i = 0; i < m; i++) if (done[i])
    {
         res.push_back(i);
         inRes[i] = true;
         vis[i] = true;
    }


    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            p[j] = j;
        }

        vector<int> gold;
        for (int i = 0; i < m; i++)
        {
            if (done[i])
            {
                 join(u[i], v[i]);
                 gold.push_back(i);
            }
        }
        for (int j = 0; j < m; j++)
        {
            if (u[j] != i && v[j] != i && getRoot(u[j]) != getRoot(v[j]))
            {
                join(u[j], v[j]);
                gold.push_back(j);
            }
        }

        int best = 0;
        for (auto next : adj[i])
        {
            if (inRes[next[1]] && !done[next[1]] && getRoot(i) != getRoot(next[0]))
            {
                gold.push_back(next[1]);
                //cout << gold.size() << endl;
                int quer = count_common_roads(gold);
                gold.pop_back();
                best = quer;
                break;
            }
        }

        vector<int> toAdd;
        for (auto next : adj[i])
        {
            if (vis[next[1]]) continue;
            vis[next[1]] = true;
            if (getRoot(i) != getRoot(next[0]))
            {
                gold.push_back(next[1]);
                //cout << gold.size() << endl;
                int quer = count_common_roads(gold);
                gold.pop_back();
                if (quer == best)
                {
                    toAdd.push_back(next[1]);
                } else if (quer > best)
                {
                    best = quer;
                    toAdd.clear();
                    toAdd.push_back(next[1]);
                }
            }
        }



        for (int edge : toAdd)
        {
            res.push_back(edge);
            inRes[edge] = true;
        }
    }



    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB correct
2 Correct 6 ms 7372 KB correct
3 Correct 5 ms 7376 KB correct
4 Correct 5 ms 7372 KB correct
5 Correct 5 ms 7372 KB correct
6 Correct 5 ms 7372 KB correct
7 Correct 6 ms 7372 KB correct
8 Correct 5 ms 7372 KB correct
9 Correct 5 ms 7264 KB correct
10 Correct 5 ms 7372 KB correct
11 Correct 5 ms 7372 KB correct
12 Correct 5 ms 7372 KB correct
13 Correct 5 ms 7372 KB correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB correct
2 Correct 6 ms 7372 KB correct
3 Correct 5 ms 7376 KB correct
4 Correct 5 ms 7372 KB correct
5 Correct 5 ms 7372 KB correct
6 Correct 5 ms 7372 KB correct
7 Correct 6 ms 7372 KB correct
8 Correct 5 ms 7372 KB correct
9 Correct 5 ms 7264 KB correct
10 Correct 5 ms 7372 KB correct
11 Correct 5 ms 7372 KB correct
12 Correct 5 ms 7372 KB correct
13 Correct 5 ms 7372 KB correct
14 Correct 8 ms 7372 KB correct
15 Correct 8 ms 7372 KB correct
16 Correct 8 ms 7372 KB correct
17 Correct 8 ms 7372 KB correct
18 Correct 6 ms 7372 KB correct
19 Correct 8 ms 7372 KB correct
20 Correct 9 ms 7372 KB correct
21 Correct 7 ms 7372 KB correct
22 Correct 7 ms 7372 KB correct
23 Correct 7 ms 7372 KB correct
24 Correct 7 ms 7372 KB correct
25 Correct 6 ms 7372 KB correct
26 Correct 6 ms 7372 KB correct
27 Correct 7 ms 7372 KB correct
28 Correct 6 ms 7372 KB correct
29 Correct 5 ms 7372 KB correct
30 Correct 6 ms 7372 KB correct
31 Correct 6 ms 7308 KB correct
32 Correct 6 ms 7372 KB correct
33 Correct 8 ms 7372 KB correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB correct
2 Correct 6 ms 7372 KB correct
3 Correct 5 ms 7376 KB correct
4 Correct 5 ms 7372 KB correct
5 Correct 5 ms 7372 KB correct
6 Correct 5 ms 7372 KB correct
7 Correct 6 ms 7372 KB correct
8 Correct 5 ms 7372 KB correct
9 Correct 5 ms 7264 KB correct
10 Correct 5 ms 7372 KB correct
11 Correct 5 ms 7372 KB correct
12 Correct 5 ms 7372 KB correct
13 Correct 5 ms 7372 KB correct
14 Correct 8 ms 7372 KB correct
15 Correct 8 ms 7372 KB correct
16 Correct 8 ms 7372 KB correct
17 Correct 8 ms 7372 KB correct
18 Correct 6 ms 7372 KB correct
19 Correct 8 ms 7372 KB correct
20 Correct 9 ms 7372 KB correct
21 Correct 7 ms 7372 KB correct
22 Correct 7 ms 7372 KB correct
23 Correct 7 ms 7372 KB correct
24 Correct 7 ms 7372 KB correct
25 Correct 6 ms 7372 KB correct
26 Correct 6 ms 7372 KB correct
27 Correct 7 ms 7372 KB correct
28 Correct 6 ms 7372 KB correct
29 Correct 5 ms 7372 KB correct
30 Correct 6 ms 7372 KB correct
31 Correct 6 ms 7308 KB correct
32 Correct 6 ms 7372 KB correct
33 Correct 8 ms 7372 KB correct
34 Correct 300 ms 8460 KB correct
35 Correct 285 ms 8524 KB correct
36 Correct 194 ms 8424 KB correct
37 Correct 26 ms 7372 KB correct
38 Correct 289 ms 8776 KB correct
39 Correct 262 ms 8564 KB correct
40 Correct 209 ms 8444 KB correct
41 Correct 288 ms 8664 KB correct
42 Correct 298 ms 8768 KB correct
43 Correct 154 ms 8236 KB correct
44 Correct 132 ms 7884 KB correct
45 Correct 149 ms 8012 KB correct
46 Correct 119 ms 8024 KB correct
47 Correct 55 ms 7660 KB correct
48 Correct 12 ms 7312 KB correct
49 Correct 22 ms 7472 KB correct
50 Correct 55 ms 7544 KB correct
51 Correct 153 ms 8004 KB correct
52 Correct 128 ms 8008 KB correct
53 Correct 115 ms 7884 KB correct
54 Correct 156 ms 8132 KB correct
55 Correct 141 ms 8012 KB correct
56 Correct 137 ms 8012 KB correct
57 Correct 135 ms 8028 KB correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB correct
2 Correct 5 ms 7372 KB correct
3 Incorrect 193 ms 10608 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB correct
2 Correct 6 ms 7372 KB correct
3 Correct 5 ms 7376 KB correct
4 Correct 5 ms 7372 KB correct
5 Correct 5 ms 7372 KB correct
6 Correct 5 ms 7372 KB correct
7 Correct 6 ms 7372 KB correct
8 Correct 5 ms 7372 KB correct
9 Correct 5 ms 7264 KB correct
10 Correct 5 ms 7372 KB correct
11 Correct 5 ms 7372 KB correct
12 Correct 5 ms 7372 KB correct
13 Correct 5 ms 7372 KB correct
14 Correct 8 ms 7372 KB correct
15 Correct 8 ms 7372 KB correct
16 Correct 8 ms 7372 KB correct
17 Correct 8 ms 7372 KB correct
18 Correct 6 ms 7372 KB correct
19 Correct 8 ms 7372 KB correct
20 Correct 9 ms 7372 KB correct
21 Correct 7 ms 7372 KB correct
22 Correct 7 ms 7372 KB correct
23 Correct 7 ms 7372 KB correct
24 Correct 7 ms 7372 KB correct
25 Correct 6 ms 7372 KB correct
26 Correct 6 ms 7372 KB correct
27 Correct 7 ms 7372 KB correct
28 Correct 6 ms 7372 KB correct
29 Correct 5 ms 7372 KB correct
30 Correct 6 ms 7372 KB correct
31 Correct 6 ms 7308 KB correct
32 Correct 6 ms 7372 KB correct
33 Correct 8 ms 7372 KB correct
34 Correct 300 ms 8460 KB correct
35 Correct 285 ms 8524 KB correct
36 Correct 194 ms 8424 KB correct
37 Correct 26 ms 7372 KB correct
38 Correct 289 ms 8776 KB correct
39 Correct 262 ms 8564 KB correct
40 Correct 209 ms 8444 KB correct
41 Correct 288 ms 8664 KB correct
42 Correct 298 ms 8768 KB correct
43 Correct 154 ms 8236 KB correct
44 Correct 132 ms 7884 KB correct
45 Correct 149 ms 8012 KB correct
46 Correct 119 ms 8024 KB correct
47 Correct 55 ms 7660 KB correct
48 Correct 12 ms 7312 KB correct
49 Correct 22 ms 7472 KB correct
50 Correct 55 ms 7544 KB correct
51 Correct 153 ms 8004 KB correct
52 Correct 128 ms 8008 KB correct
53 Correct 115 ms 7884 KB correct
54 Correct 156 ms 8132 KB correct
55 Correct 141 ms 8012 KB correct
56 Correct 137 ms 8012 KB correct
57 Correct 135 ms 8028 KB correct
58 Correct 4 ms 7372 KB correct
59 Correct 5 ms 7372 KB correct
60 Incorrect 193 ms 10608 KB WA in grader: NO
61 Halted 0 ms 0 KB -