Submission #293077

# Submission time Handle Problem Language Result Execution time Memory
293077 2020-09-07T16:00:35 Z Saboon Simurgh (IOI17_simurgh) C++17
51 / 100
176 ms 4348 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> 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);
    vector<int> Q(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], me = -1;
        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;
    }
    int now = 0;
    for (int i = 0; i < m; i++)
        if (abs(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:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     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 1280 KB correct
9 Correct 1 ms 1280 KB correct
10 Correct 1 ms 1280 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 1280 KB correct
9 Correct 1 ms 1280 KB correct
10 Correct 1 ms 1280 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 3 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 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 2 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1312 KB correct
27 Correct 2 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 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 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 1280 KB correct
9 Correct 1 ms 1280 KB correct
10 Correct 1 ms 1280 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 3 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 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 2 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1312 KB correct
27 Correct 2 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 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 ms 1408 KB correct
34 Correct 174 ms 2304 KB correct
35 Correct 170 ms 2808 KB correct
36 Correct 114 ms 2304 KB correct
37 Correct 9 ms 1408 KB correct
38 Correct 176 ms 2560 KB correct
39 Correct 147 ms 2432 KB correct
40 Correct 118 ms 2304 KB correct
41 Correct 173 ms 2560 KB correct
42 Correct 174 ms 2680 KB correct
43 Correct 87 ms 2296 KB correct
44 Correct 72 ms 1920 KB correct
45 Correct 84 ms 1920 KB correct
46 Correct 64 ms 1792 KB correct
47 Correct 28 ms 1536 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 8 ms 1408 KB correct
50 Correct 28 ms 1536 KB correct
51 Correct 84 ms 1920 KB correct
52 Correct 72 ms 1920 KB correct
53 Correct 65 ms 1792 KB correct
54 Correct 92 ms 2176 KB correct
55 Correct 87 ms 1920 KB correct
56 Correct 87 ms 1920 KB correct
57 Correct 91 ms 2040 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Incorrect 141 ms 4348 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 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 1280 KB correct
9 Correct 1 ms 1280 KB correct
10 Correct 1 ms 1280 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 3 ms 1408 KB correct
15 Correct 3 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 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 2 ms 1408 KB correct
25 Correct 1 ms 1408 KB correct
26 Correct 2 ms 1312 KB correct
27 Correct 2 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 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 ms 1408 KB correct
34 Correct 174 ms 2304 KB correct
35 Correct 170 ms 2808 KB correct
36 Correct 114 ms 2304 KB correct
37 Correct 9 ms 1408 KB correct
38 Correct 176 ms 2560 KB correct
39 Correct 147 ms 2432 KB correct
40 Correct 118 ms 2304 KB correct
41 Correct 173 ms 2560 KB correct
42 Correct 174 ms 2680 KB correct
43 Correct 87 ms 2296 KB correct
44 Correct 72 ms 1920 KB correct
45 Correct 84 ms 1920 KB correct
46 Correct 64 ms 1792 KB correct
47 Correct 28 ms 1536 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 8 ms 1408 KB correct
50 Correct 28 ms 1536 KB correct
51 Correct 84 ms 1920 KB correct
52 Correct 72 ms 1920 KB correct
53 Correct 65 ms 1792 KB correct
54 Correct 92 ms 2176 KB correct
55 Correct 87 ms 1920 KB correct
56 Correct 87 ms 1920 KB correct
57 Correct 91 ms 2040 KB correct
58 Correct 1 ms 1408 KB correct
59 Correct 1 ms 1408 KB correct
60 Incorrect 141 ms 4348 KB WA in grader: NO
61 Halted 0 ms 0 KB -