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 "plants.h"
#include <bits/stdc++.h>
using namespace std;
const int N=200100;
int cp[N],od[N],deg[N];
vector<int> ma[N];
void init(int k, std::vector<int> r) {
int n=r.size();
for(int i=0;i<n;i++)
{
int j=(i+1)%n;
if(r[i]==0)
{
// j -> i
deg[i]++;
ma[j].push_back(i);
}
else
{
// i -> j
deg[j]++;
ma[i].push_back(j);
}
}
int cnt=0;
queue<int> cur;
for(int i=0;i<n;i++)
{
if(deg[i]==0 and cp[i]==0)
{
cnt++;
cp[i]=cnt;
od[i]=0;
cur.push(i);
}
}
while(cur.size()>0)
{
int f=cur.front();
cur.pop();
for(auto s:ma[f])
{
deg[s]--;
if(deg[s]==0)
{
od[s]=od[f]+1;
cp[s]=cp[f];
cur.push(s);
}
}
}
return;
}
int compare_plants(int x, int y) {
if(cp[x]==cp[y])
{
if(od[x]==od[y])return 0;
return ((od[x]<od[y])?-1:1);
}
else
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |