제출 #853756

#제출 시각아이디문제언어결과실행 시간메모리
853756hngwlog슈퍼트리 잇기 (IOI20_supertrees)C++14
21 / 100
182 ms22152 KiB
#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 && p[i][j] != 1) return 0; if (p[i][j] > 2) return 0; if (p[i][j] == 2) unite(i, j); } vector<vector<int>> adj(n); REP(i, n) adj[getroot(i)].push_back(i); vector<pair<int, int>> ans; REP(i, n) REP(j, _size(adj[i]) - 1) ans.push_back({adj[i][j], adj[i][j + 1]}); REP(i, n) REP(j, n) { if (p[i][j] != 1 || i == j) continue; if (unite(i, j)) ans.push_back({i, j}); } REP(i, n) REP(j, n) { if (p[i][j] != 0) continue; if (getroot(i) == getroot(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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...