답안 #1067272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067272 2024-08-20T13:48:51 Z Ignut Simurgh (IOI17_simurgh) C++17
30 / 100
177 ms 2652 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]);
        bool got = false;
        vector<int> asked;
        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) {
                got = true;
                ans[i] = true;
                have = next_have;
                break;
            }
            else {
                asked.push_back(i);
            }
            next_have.pop_back();
        }
        if (!got) {
            ans[del_val] = true;
        }
        else {
            for (int j : asked) bad[j] = true;
        }
        cnt = count_common_roads(have);
    }
    return have;   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 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 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 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 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 344 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 0 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 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 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 344 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 0 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 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 177 ms 1116 KB correct
35 Correct 161 ms 1416 KB correct
36 Correct 123 ms 1212 KB correct
37 Correct 19 ms 528 KB correct
38 Incorrect 164 ms 1448 KB WA in grader: NO
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 157 ms 2652 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 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 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 344 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 0 ms 348 KB correct
23 Correct 0 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 0 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 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 177 ms 1116 KB correct
35 Correct 161 ms 1416 KB correct
36 Correct 123 ms 1212 KB correct
37 Correct 19 ms 528 KB correct
38 Incorrect 164 ms 1448 KB WA in grader: NO
39 Halted 0 ms 0 KB -