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 "garden.h"
#include "gardenlib.h"
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,L[150009],LL[150009],P,K,pas,bo[300009],msh[150009],MSH[150009],msh2[150009],MSH2[150009];
vector <int> v[300009];
vector <pair <int, int> > VP[300009];
void dfs(int q, int rr){
int qa=q/2;
if(rr==K){
if(bo[qa]!=t&&q%2==0){
bo[qa]=t;pas++;
}
return;
}
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
dfs((*it),rr+1);
}
}
void count_routes(int NN, int MM, int PP, int RR[][2], int QQ, int GG[])
{
a=NN;b=MM;P=PP+1;tes=QQ;
for(i=1; i<=a; i++){
L[i]=b+5;
}
for(i=1; i<=b; i++){
c=RR[i-1][0]+1;d=RR[i-1][1]+1;
VP[c].push_back({i,d});
VP[d].push_back({i,c});
if(L[c]==b+5){
L[c]=i;LL[c]=d;
}
if(L[d]==b+5){
L[d]=i;LL[d]=c;
}
}
for(i=1; i<=a; i++){
sort(VP[i].begin(),VP[i].end());
msh[i]=VP[i][0].second;MSH[i]=VP[i][0].first;
if(VP[i].size()==1){
msh2[i]=VP[i][0].second;MSH2[i]=VP[i][0].first;
}else{
msh2[i]=VP[i][1].second;MSH2[i]=VP[i][1].first;
}
}
for(i=1; i<=a; i++){
ii=0;
if(L[msh[i]]!=MSH[i]){
j=msh[i];jj=0;
}else{
j=msh[i];jj=1;
}
v[j*2+jj].push_back(i*2+ii);
ii=1;
if(L[msh2[i]]!=MSH2[i]){
j=msh2[i];jj=0;
}else{
j=msh2[i];jj=1;
}
v[j*2+jj].push_back(i*2+ii);
}
for(t=1; t<=tes; t++){
K=GG[t-1];pas=0;
dfs(P*2,0);dfs(P*2+1,0);
answer(pas);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |