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 <bits/stdc++.h>
#include "gift.h"
using namespace std;
vector<int>parent;
void init(int n) { parent.resize(n); for(int l=0;l<n;l++) parent[l]=l; }
int findset(int n) { return (parent[n]==n)?n:(parent[n]=findset(parent[n])); }
bool sameSet(int a, int b) { return findset(a)==findset(b); }
void unionSet(int a, int b) {
if(sameSet(a, b)) return;
a=findset(a); b=findset(b);
if(a < b)
parent[a]=b;
else parent[b] = a;
}
int construct(int n, int r, std::vector<int> a, std::vector<int> b, std::vector<int> x) {
init(n+1);
for(int i = 0; i < r; i++){
if(x[i] == 2) continue;
int j = findset(a[i]);
while(j<b[i]&&findset(j) != findset(b[i])){
unionSet(j,b[i]);
j++; j=findset(j);
}
}
for(int i=0;i<r;i++){
if(x[i]==1){
continue;
}
if(findset(a[i])==findset(b[i])){
return 0;
}
}
string s ="R";
for(int i=1;i<n;i++)
{
if(findset(i) != findset(i-1)) {
if(s.back() == 'R')s += "B";
else s+= "R";
}
else s+= s.back();
}
craft(s);
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... |