# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
679458 | qwerasdfzxcl | Collapse (JOI18_collapse) | C++17 | 3218 ms | 26612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "collapse.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
constexpr int B = 1001;
struct DSU{
int path[100100], sz[100100], cnt;
vector<pair<int, int>> mylog;
void init(int n){for (int i=1;i<=n;i++){path[i] = i; sz[i] = 1;} mylog.clear(); cnt = 0;}
int find(int s){
if (s==path[s]) return s;
return find(path[s]);
}
bool merge(int x, int y){
//printf("merge: %d %d\n", x, y);
x = find(x), y = find(y);
if (x==y) return 0;
cnt++;
if (sz[x] > sz[y]) swap(x, y);
path[x] = y;
sz[y] += sz[x];
mylog.emplace_back(x, sz[x]);
return 1;
}
void rollback(int c){
while(c--){
auto [x, _sz] = mylog.back(); mylog.pop_back();
sz[path[x]] -= _sz;
Compilation message (stderr)
# | 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... |