# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365005 | tatyam | 자매 도시 (APIO20_swap) | C++17 | 456 ms | 23660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct UnionFind{
vector<vector<pair<int, int>>> data;
vector<int> flag_time, degree;
UnionFind(int n = 0): data(n, {{-1, -1}}), flag_time(n, INT_MAX), degree(n){}
int merged_time(int x) const {
const auto [time, root] = data[x].back();
if(root < 0) return INT_MAX;
return time;
}
int root(int t, int x) const { // after t
if(t < merged_time(x)) return x;
return root(t, data[x].back().second);
}
bool unite(int t, int x, int y){
bool flag = ++degree[x] >= 3 || ++degree[y] >= 3;
x = root(t, x);
y = root(t, y);
if(x == y){
if(flag_time[x] == INT_MAX) flag_time[x] = t;
return 0;
}
const int size_x = data[x].back().second, size_y = data[y].back().second;
if(size_x > size_y) swap(x, y);
if(flag_time[x] == INT_MAX && (flag || flag_time[y] != INT_MAX)) flag_time[x] = t;
data[x].emplace_back(t, size_x + size_y);
data[y].emplace_back(t, x);
return 1;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |