답안 #619755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
619755 2022-08-02T15:35:28 Z Sergio_2357 Simurgh (IOI17_simurgh) C++17
0 / 100
3000 ms 212 KB
#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

struct DSU {
    vi v, sz;
    int cg;
    int find(int x)
    {
        if (v[x] == -1)
            return x;
        v[x] = find(v[x]);
        return v[x];
    }
    void join(int a, int b)
    {
        a = find(a);
        b = find(b);
        if (a == b)
            return;
        cg--;
        if (sz[a] > sz[b])
            swap(a, b);
        v[a] = b;
        sz[b] += sz[a];
    }
    DSU(int n)
    {
        v = vi(n + 10, -1);
        sz = vi(n + 10, 1);
        cg = n;
    }
};

bool test(vi u, vi v)
{
    DSU dsu(u.size());
    for (int i = 0; i < u.size(); i++)
        dsu.join(u[i], v[i]);
    return dsu.cg == 1;
}

vi to_list(int b, int ma)
{
    vi r;
    for (int i = 0; i < ma; i++) {
        if (b & (1ll << i))
            r.push_back(i);
    }
    return r;
}

vi find_roads(int n, vi u, vi v)
{
    //cout << "YES" << endl;
    for (int b = 0; b < (1ll << (u.size())); b++) {
        vi tu, tv;
        vi lst = to_list(b, u.size());
        for (int x : lst) {
            tu.push_back(u[x]);
            tv.push_back(v[x]);
        }
        if (lst.size() == n - 1 && test(tu, tv) && (count_common_roads(lst) == (n - 1))) {
            return lst;
        }
    }
    while (true) {
        //Cry
    }
    return to_list((1ll << (n - 1)) - 1, n);
}

Compilation message

simurgh.cpp: In function 'bool test(vi, vi)':
simurgh.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < u.size(); i++)
      |                     ~~^~~~~~~~~~
simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:66:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         if (lst.size() == n - 1 && test(tu, tv) && (count_common_roads(lst) == (n - 1))) {
      |             ~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3067 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -