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 "railroad.h"
#include<bits/stdc++.h>
using namespace std;
int p[2000005],a[2000005];
int fp(int a){
return p[a]==a?a:p[a]=fp(p[a]);
}
void un(int a,int b){
p[fp(a)]=fp(b);
}
vector<int>ids;
map<int,int>mp;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
vector<int> ids;
for(int i=0;i<n;i++){
ids.push_back(s[i]);
ids.push_back(t[i]);
}
sort(ids.begin(),ids.end());
ids.erase(unique(ids.begin(),ids.end()),ids.end());
int m=ids.size();
for(int i=1;i<=m;i++)p[i]=i;
for(int i=0;i<n;i++){
s[i]=lower_bound(ids.begin(),ids.end(),s[i])-ids.begin()+1;
t[i]=lower_bound(ids.begin(),ids.end(),t[i])-ids.begin()+1;
un(s[i],t[i]);
a[s[i]]++,a[t[i]]--;
}
int val=0;
for(int i=1;i<m;){
val+=a[i];
if(val>1)return 1;
else if(val<1)un(i,i+1);
}
for(int i=1;i<=m;i++){
if(fp(i)!=fp(1))return 1;
}
return 0;
}
# | 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... |