# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205190 | puppies_and_rainbows | Roller Coaster Railroad (IOI16_railroad) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
#define int long long
using namespace std;
pair<int, int> a[200005], b[200005];
int f[200005], n, tot;
int find(int i)
{
return f[i]==i? f[i]:f[i]=find(f[i]);
}
void unionn(int i, int j)
{
f[find(i)]=find(j);
tot--;
}
int plan_roller_coaster(vector<int> s, vector<int> t)
{
s.push_back(1000000000);
t.push_back(1);
n=s.size(), tot=n;
for(int i=1; i<=n; i++)
{
f[i]=i;
a[i]={s[i-1], i};
b[i]={t[i-1], i};
}
sort(a+1, a+n+1);
sort(b+1, b+n+1);
for(int i=1; i<=n; i++)
{
if(a[i].first<b[i].first) return 1;
unionn(a[i].second, b[i].second);
}
for(int i=1; i<n; i++)
{
if(find(a[i].second)!=find(a[i+1].second))
{
if(a[i].first>b[i+1].first)
{
unionn(a[i].second, a[i+1].second);
}
}
}
if(tot==1) return 0;
else return 1;
}