Submission #293102

# Submission time Handle Problem Language Result Execution time Memory
293102 2020-09-07T16:22:36 Z Saboon Simurgh (IOI17_simurgh) C++17
70 / 100
234 ms 7800 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 500 + 10;

vector<pair<int,int>> g[maxn];
int par[maxn], parindex[maxn], h[maxn];
bool visited[maxn];
int Cost, c[maxn*maxn];

void dfs(int v){
    visited[v] = 1;
    for (auto [u,idx] : g[v]){
        if (!visited[u]){
            h[u] = h[v]+1;
            par[u] = v;
            parindex[u] = idx;
            dfs(u);
        }
    }
}

bool eq[maxn];
vector<int> Q;
vector<int> Dw[maxn];
vector<int> Ed[maxn];
int sz[maxn];

void solve(int l, int r, int x){
    if (l >= r)
        return;
    int AllZero = Cost;
    for (int i = l; i < r; i++){
        Q[Dw[x][i]-1] = Ed[x][i];
        AllZero -= c[parindex[Dw[x][i]]];
    }
    int Tmp = count_common_roads(Q);
    for (int i = l; i < r; i++)
        Q[Dw[x][i]-1] = parindex[Dw[x][i]];
    if (Tmp != AllZero){
        if (l+1 == r){
            c[Ed[x][l]] = 1;
            return;
        }
        int mid = (l+r)>>1;
        solve(l,mid,x);
        solve(mid,r,x);
    }
    for (int i = l; i < r; i++)
        Q[Dw[x][i]-1] = parindex[Dw[x][i]];
}

vector<int> find_roads(int n, vector<int> u, vector<int> v){
    int m = v.size();
    for (int i = 0; i < v.size(); i++){
        g[v[i]].push_back({u[i],i});
        g[u[i]].push_back({v[i],i});
    }
    dfs(0);
    Q.resize(n-1);
    for (int i = 1; i < n; i++)
        Q[i-1] = parindex[i];
    Cost = count_common_roads(Q);
    memset(c, -1, sizeof c);
    for (int i = 0; i < m; i++){
        if (h[v[i]] > h[u[i]])
            swap(v[i],u[i]);
        if (par[u[i]] == v[i])
            continue;
        int x = u[i], found = 0, me = -1;
        while (x != v[i]){
            if (c[parindex[x]] == -1)
                found = 1;
            x = par[x];
        }
        if (!found)
            continue;
        x = u[i];
        while (x != v[i]){
            if (c[parindex[x]] != -1 and me != -1){
                x = par[x];
                continue;
            }
            Q[x-1] = i;
            int Tmp = count_common_roads(Q);
            if (c[parindex[x]] != -1){
                if (Tmp == Cost)
                    me = c[parindex[x]];
                else
                    me = 1-c[parindex[x]];
           }
            else{
                if (Tmp == Cost)
                    eq[x] = 1;
                else if (Tmp > Cost)
                    eq[x] = 0, me = 1;
                else
                    eq[x] = 0, me = 0;
            }
            Q[x-1] = parindex[x];
            x = par[x];
        }
        if (me == -1)
            me = 0;
        x = u[i];
        while (x != v[i]){
            if (c[parindex[x]] == -1){
                if (eq[x])
                    c[parindex[x]] = me;
                else
                    c[parindex[x]] = 1-me;
            }
            x = par[x];
        }
        c[i] = me;
    }
    for (int i = 1; i < n; i++)
        c[parindex[i]] = abs(c[parindex[i]]);
    for (int i = 0; i < m; i++){
        if (c[i] != -1)
            continue;
        Dw[sz[u[i]]].push_back(u[i]);
        Ed[sz[u[i]]].push_back(i);
        sz[u[i]] ++;
    }
    for (int i = 0; i < n; i++)
        solve(0, Dw[i].size(), i);
    int now = 0;
    for (int i = 0; i < m; i++)
        if (c[i] == 1)
            Q[now++] = i;
    return Q;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for (int i = 0; i < v.size(); i++){
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 2 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 2 ms 1408 KB correct
17 Correct 2 ms 1440 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 2 ms 1408 KB correct
20 Correct 2 ms 1408 KB correct
21 Correct 2 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 1 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 1 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 1 ms 1408 KB correct
32 Correct 1 ms 1408 KB correct
33 Correct 1 ms 1408 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 2 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 2 ms 1408 KB correct
17 Correct 2 ms 1440 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 2 ms 1408 KB correct
20 Correct 2 ms 1408 KB correct
21 Correct 2 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 1 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 1 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 1 ms 1408 KB correct
32 Correct 1 ms 1408 KB correct
33 Correct 1 ms 1408 KB correct
34 Correct 39 ms 2688 KB correct
35 Correct 39 ms 2560 KB correct
36 Correct 33 ms 2432 KB correct
37 Correct 9 ms 1408 KB correct
38 Correct 40 ms 2688 KB correct
39 Correct 44 ms 2560 KB correct
40 Correct 33 ms 2432 KB correct
41 Correct 42 ms 2688 KB correct
42 Correct 41 ms 2560 KB correct
43 Correct 14 ms 2124 KB correct
44 Correct 11 ms 1920 KB correct
45 Correct 12 ms 2048 KB correct
46 Correct 12 ms 1920 KB correct
47 Correct 6 ms 1664 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 4 ms 1408 KB correct
50 Correct 6 ms 1664 KB correct
51 Correct 12 ms 2048 KB correct
52 Correct 11 ms 1920 KB correct
53 Correct 10 ms 1920 KB correct
54 Correct 13 ms 2176 KB correct
55 Correct 13 ms 2048 KB correct
56 Correct 14 ms 2048 KB correct
57 Correct 13 ms 2048 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 131 ms 5240 KB correct
4 Correct 219 ms 7672 KB correct
5 Correct 217 ms 7672 KB correct
6 Correct 214 ms 7676 KB correct
7 Correct 233 ms 7800 KB correct
8 Correct 232 ms 7800 KB correct
9 Correct 222 ms 7672 KB correct
10 Correct 234 ms 7672 KB correct
11 Correct 234 ms 7672 KB correct
12 Correct 221 ms 7672 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 217 ms 7672 KB correct
15 Correct 222 ms 7672 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 2 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 2 ms 1408 KB correct
17 Correct 2 ms 1440 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 2 ms 1408 KB correct
20 Correct 2 ms 1408 KB correct
21 Correct 2 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 1 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 1 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 1 ms 1408 KB correct
32 Correct 1 ms 1408 KB correct
33 Correct 1 ms 1408 KB correct
34 Correct 39 ms 2688 KB correct
35 Correct 39 ms 2560 KB correct
36 Correct 33 ms 2432 KB correct
37 Correct 9 ms 1408 KB correct
38 Correct 40 ms 2688 KB correct
39 Correct 44 ms 2560 KB correct
40 Correct 33 ms 2432 KB correct
41 Correct 42 ms 2688 KB correct
42 Correct 41 ms 2560 KB correct
43 Correct 14 ms 2124 KB correct
44 Correct 11 ms 1920 KB correct
45 Correct 12 ms 2048 KB correct
46 Correct 12 ms 1920 KB correct
47 Correct 6 ms 1664 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 4 ms 1408 KB correct
50 Correct 6 ms 1664 KB correct
51 Correct 12 ms 2048 KB correct
52 Correct 11 ms 1920 KB correct
53 Correct 10 ms 1920 KB correct
54 Correct 13 ms 2176 KB correct
55 Correct 13 ms 2048 KB correct
56 Correct 14 ms 2048 KB correct
57 Correct 13 ms 2048 KB correct
58 Correct 1 ms 1408 KB correct
59 Correct 1 ms 1408 KB correct
60 Correct 131 ms 5240 KB correct
61 Correct 219 ms 7672 KB correct
62 Correct 217 ms 7672 KB correct
63 Correct 214 ms 7676 KB correct
64 Correct 233 ms 7800 KB correct
65 Correct 232 ms 7800 KB correct
66 Correct 222 ms 7672 KB correct
67 Correct 234 ms 7672 KB correct
68 Correct 234 ms 7672 KB correct
69 Correct 221 ms 7672 KB correct
70 Correct 1 ms 1408 KB correct
71 Correct 217 ms 7672 KB correct
72 Correct 222 ms 7672 KB correct
73 Correct 2 ms 1536 KB correct
74 Incorrect 219 ms 7712 KB WA in grader: NO
75 Halted 0 ms 0 KB -