| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1356682 | Faisal_Saqib | Fountain Parks (IOI21_parks) | C++17 | 310 ms | 38640 KiB |
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e6;
int p[N];
int get(int x)
{
return (p[x]==x)?x:p[x]=get(p[x]);
}
bool merge(int x,int y)
{
x=get(x);
y=get(y);
if(x==y)return 0;
p[x]=y;
return 1;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n=x.size();
map<pair<int,int>,int> ind;
for(int i=0;i<n;i++)
{
p[i]=i;
ind[{x[i],y[i]}]=i;
}
vector<int> u,v,a,b;
for(int i=0;i<n;i++)
{
auto it=ind.find({x[i]-2,y[i]});
int j=ind[{x[i]-2,y[i]}];
if(it!=ind.end() and merge(i,j))
{
u.push_back(j);
v.push_back(i);
a.push_back(x[i]-1);
b.push_back(y[i]+1);
}
it=ind.find({x[i],y[i]-2});
j=ind[{x[i],y[i]-2}];
if(it!=ind.end() and merge(i,j))
{
u.push_back(j);
v.push_back(i);
a.push_back(x[i]-((x[i]==2)?-1:+1));
b.push_back(y[i]-1);
}
}
int cn=0;
for(int i=0;i<n;i++)
{
if(get(i)==i)
{
cn++;
}
}
if(cn>1)
{
return 0;
}
build(u,v,a,b);
return 1;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
