답안 #853918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853918 2023-09-25T13:45:54 Z hngwlog 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

vector<int> root;

int getroot(int u) {

    return root[u] == u ? u : (root[u] = getroot(root[u]));
}

bool unite(int u, int v) {

    u = getroot(u), v = getroot(v);
    if (u == v) return false;
    root[v] = u;
    return true;
}

int construct(vector<vector<int>> p) {

    int n = _size(p);
    root.resize(n);
    REP(i, n) root[i] = i;
    REP(i, n) REP(j, n) {
        if (i == j) {
            if (p[i][j] != 1) return 0;
            continue;
        }
        if (p[i][j] == 1) unite(i, j);
    }
    vector<vector<int>> adj(n);
    REP(i, n) adj[getroot(i)].push_back(i);
    vector<int> used(n);
    vector<pair<int, int>> ans;
    vector<vector<int>> cnt(n, vector<int>(n));
    REP(i, n) {
        if (!_size(adj[i]) || used[i]) continue;
        FORALL(u, adj[i]) used[u]++;
        FORALL(u, adj[i]) FORALL(v, adj[i]) cnt[u][v] = 1;
        REP(j, _size(adj[i]) - 1) ans.push_back({adj[i][j], adj[i][j + 1]});
        vector<int> g;
        g.push_back(i);
        REP(j, n) if (p[i][j] == 2) {
            used[j]++;
            g.push_back(j);
        }
        if (!_size(g)) continue;
        if (_size(g) == 1) return 0;
        FORALL(u, g) FORALL(v, g) if (u != v) cnt[u][v] = 2; else cnt[u][v] = 1;
        FORALL(u, g) FORALL(v, adj[i]) {
            if (u == i || v == i) continue;
            cnt[u][v] = cnt[v][u] = 2;
        }
        REP(j, _size(g) - 1) ans.push_back({g[j], g[j + 1]});
        ans.push_back({g[0], g.back()});
    }
    REP(i, n) REP(j, n) if (cnt[i][j] != p[i][j]) return 0;
    vector<vector<int>> b(n, vector<int>(n));
    FORALL(e, ans) b[e.fi][e.se] = b[e.se][e.fi] = 1;
    build(b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -