Submission #1067294

# Submission time Handle Problem Language Result Execution time Memory
1067294 2024-08-20T14:09:46 Z Ignut Simurgh (IOI17_simurgh) C++17
51 / 100
110 ms 2780 KB
// Ignut

#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct DSU {
    vector<int> p, sz;
    void Init(int n) {
        p.assign(n, 0);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }
    int Get(int v) {
        return p[v] == v ? v : p[v] = Get(p[v]);
    }
    bool Unite(int u, int v) {
        u = Get(u), v = Get(v);
        if (u == v) return false;
        if (sz[u] > sz[v]) swap(u, v);
        sz[v] += sz[u];
        p[u] = v;
        return true;
    }
};

const int N = 555;

vector<int> g[N];

bool ans[N * N];
bool bad[N * N];

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
    int m = u.size();
    for (int i = 0; i < m; i ++) {
        g[u[i]].push_back(i);
        g[v[i]].push_back(i);
    }
    DSU dsu;
    dsu.Init(n);
    vector<int> have;
    for (int i = 0; i < m; i ++) {
        if (dsu.Unite(u[i], v[i])) {
            have.push_back(i);
        }
    }

    int cnt = count_common_roads(have);
    while (cnt < n - 1) {
        vector<int> next_have;
        int del_val = -1;
        for (int i : have) {
            if (ans[i]) continue;
            for (int j : have) if (j != i) next_have.push_back(j);
            del_val = i;
            break;
        }
        map<int, int> mp;
        for (int i : next_have) mp[i] ++;
        DSU dsu2; dsu2.Init(n);
        for (int i : next_have) dsu2.Unite(u[i], v[i]);
        vector<int> c_sm, c_eq, c_bg;
        for (int i = 0; i < m; i ++) {
            if (mp.count(i)) continue;
            if (bad[i]) continue;
            DSU dsu3 = dsu2;
            if (!dsu3.Unite(u[i], v[i])) continue;

            next_have.push_back(i);
            int c = count_common_roads(next_have);
            if (c > cnt) {
                c_bg.push_back(i);
            }
            else if (c == cnt) {
                c_eq.push_back(i);
            }
            else {
                c_sm.push_back(i);
            }
            next_have.pop_back();
        }

        next_have.clear();
        if (!c_bg.empty()) {
            for (int j : c_eq) bad[j] = true;
            for (int j : c_bg) {
                ans[j] = true;
            }
        }
        else {
            for (int j : c_sm) bad[j] = true;
            for (int j : c_eq) {
                ans[j] = true;
            }
        }
        dsu2.Init(n);
        for (int j = 0; j < m; j ++) {
            if (ans[j]) {
                next_have.push_back(j);
                dsu2.Unite(u[j], v[j]);
            }
        }
        for (int j = 0; j < m; j ++) {
            if (next_have.size() == n - 1) break;
            if (ans[j]) continue;
            if (bad[j]) continue;
            DSU dsu3 = dsu2;
            if (!dsu3.Unite(u[j], v[j])) continue;
            next_have.push_back(j);
            dsu2.Unite(u[j], v[j]);
        }
        have = next_have;
        
        cnt = count_common_roads(have);
    }
    return have;   
}


Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:107:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |             if (next_have.size() == n - 1) break;
      |                 ~~~~~~~~~~~~~~~~~^~~~~~~~
simurgh.cpp:54:13: warning: variable 'del_val' set but not used [-Wunused-but-set-variable]
   54 |         int del_val = -1;
      |             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 396 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 344 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 1 ms 596 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 464 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 396 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 344 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 1 ms 596 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 464 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 2 ms 344 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 0 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 348 KB correct
33 Correct 0 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 396 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 344 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 1 ms 596 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 464 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 2 ms 344 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 0 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 348 KB correct
33 Correct 0 ms 348 KB correct
34 Correct 106 ms 1116 KB correct
35 Correct 89 ms 1112 KB correct
36 Correct 66 ms 1112 KB correct
37 Correct 7 ms 348 KB correct
38 Correct 81 ms 1360 KB correct
39 Correct 87 ms 1368 KB correct
40 Correct 58 ms 1116 KB correct
41 Correct 36 ms 1372 KB correct
42 Correct 94 ms 1480 KB correct
43 Correct 2 ms 856 KB correct
44 Correct 2 ms 636 KB correct
45 Correct 3 ms 860 KB correct
46 Correct 2 ms 604 KB correct
47 Correct 1 ms 604 KB correct
48 Correct 0 ms 348 KB correct
49 Correct 1 ms 528 KB correct
50 Correct 1 ms 604 KB correct
51 Correct 2 ms 860 KB correct
52 Correct 2 ms 860 KB correct
53 Correct 2 ms 604 KB correct
54 Correct 3 ms 940 KB correct
55 Correct 2 ms 860 KB correct
56 Correct 4 ms 720 KB correct
57 Correct 3 ms 860 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 110 ms 2780 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 396 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 344 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 1 ms 596 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 464 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 2 ms 344 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 0 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 348 KB correct
33 Correct 0 ms 348 KB correct
34 Correct 106 ms 1116 KB correct
35 Correct 89 ms 1112 KB correct
36 Correct 66 ms 1112 KB correct
37 Correct 7 ms 348 KB correct
38 Correct 81 ms 1360 KB correct
39 Correct 87 ms 1368 KB correct
40 Correct 58 ms 1116 KB correct
41 Correct 36 ms 1372 KB correct
42 Correct 94 ms 1480 KB correct
43 Correct 2 ms 856 KB correct
44 Correct 2 ms 636 KB correct
45 Correct 3 ms 860 KB correct
46 Correct 2 ms 604 KB correct
47 Correct 1 ms 604 KB correct
48 Correct 0 ms 348 KB correct
49 Correct 1 ms 528 KB correct
50 Correct 1 ms 604 KB correct
51 Correct 2 ms 860 KB correct
52 Correct 2 ms 860 KB correct
53 Correct 2 ms 604 KB correct
54 Correct 3 ms 940 KB correct
55 Correct 2 ms 860 KB correct
56 Correct 4 ms 720 KB correct
57 Correct 3 ms 860 KB correct
58 Correct 0 ms 348 KB correct
59 Correct 0 ms 348 KB correct
60 Incorrect 110 ms 2780 KB WA in grader: NO
61 Halted 0 ms 0 KB -