답안 #502903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502903 2022-01-06T18:09:28 Z LouayFarah 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1 ms 332 KB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};

void build(vector<vector<int>> b);

struct dsu
{
    vector<int> len;
    vector<int> link;

    void init(int n)
    {
        len.assign(n, 1);
        link.assign(n, 0);
        for(int i = 0; i<n; i++)
        {
            link[i] = i;
        }
    }

    int search(int x)
    {
        if(x!=link[x])
            link[x] = search(link[x]);
        return link[x];
    }

    bool check(int a, int b)
    {
        return search(a)==search(b);
    }

    void join(int a, int b)
    {
        a = search(a);
        b = search(b);

        if(a!=b)
        {
            if(len[a]<len[b])
                swap(a, b);

            len[a]+=len[b];
            link[b] = a;
        }
    }
};

int construct(vector<vector<int>> p)
{
    int n = int(p[0].size());

    vector<vector<int>> b(n, vector<int>(n, 0));

    dsu d;
    d.init(n);

    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; j<n; j++)
        {
            if(p[i][j]==1)
                d.join(i, j);
        }
    }

    vector<set<int>> groups(n);
    for(int i = 0; i<n; i++)
    {
        int parent = d.search(i);
        groups[parent].insert(i);
    }

    for(int i = 0; i<n; i++)
    {
        if(groups[i].empty())
            continue;

        for(auto it = groups[i].begin(); it!=groups[i].end(); it++)
        {
            int A = *(it);
            it++;
            int B = *(it);

            bool flag = false;
            if(it==groups[i].end())
                flag = true;
            it--;

            b[A][B] = 1;
            b[B][A] = 1;

            if(flag)
                break;
        }
    }

    build(b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB b[1][1] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB b[1][1] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -