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 "garden.h"
#include "gardenlib.h"
#include <iostream>
#include <cstdlib>
#define maxn 10005
using namespace std;
int map[2*maxn][3],o;
int real_map[2*maxn][3];
int sort[maxn][3];
int ans=0;
int t[2*maxn];
int compare(const void*x ,const void *y)
{
return ((int*)y)[2] - ((int*)x)[2];
}
void find(int x, int location, int g, int lp)
{
// cout<<x<<"\t"<<location<<"\t"<<g<<endl;
if(g==0)
{
if(x==location)ans++;
return ;
}
int p=x;
p=real_map[p][0];
if(real_map[p][1]==lp)p=real_map[p][0];
if(p==-1)find(lp,location,g-1,x);
else find(real_map[p][1],location,g-1,x);
}
void count_routes(int n, int m, int location, int r[][2], int q, int g[])
{
//Q=1
for(int i=0;i<2*maxn;i++)
{
map[i][0]=-1;
real_map[i][0]=-1;
t[i]=0;
}
o=n-1;
for(int i=0;i<m;i++)
{
o++;
map[o][1]=r[i][1];
map[o][2]=i;
map[o][0]=map[r[i][0]][0];
map[r[i][0]][0]=o;
o++;
map[o][1]=r[i][0];
map[o][2]=i;
map[o][0]=map[r[i][1]][0];
map[r[i][1]][0]=o;
}
/* for(int i=0;i<=o;i++)cout<<i<<"\t";cout<<endl;
for(int i=0;i<=o;i++)cout<<map[i][0]<<"\t";cout<<endl;
for(int i=0;i<=o;i++)cout<<map[i][1]<<"\t";cout<<endl;*/
o=n-1;
for(int i=0;i<m;i++)//編號越少越美麗
{
int oo=0;
int p=i;
while(map[p][0]!=-1)
{
p=map[p][0];
oo++;
sort[oo][0]=i;
sort[oo][1]=map[p][1];
sort[oo][2]=map[p][2];
}
qsort(sort+1,oo,sizeof(int)*3,compare);
for(int j=1;j<=oo;j++)
{
o++;
real_map[o][1]=sort[j][1];
real_map[o][2]=sort[j][2];
real_map[o][0]=real_map[i][0];
real_map[i][0]=o;
}
}
/* for(int i=0;i<=o+2;i++)cout<<i<<"\t";cout<<endl;
for(int i=0;i<=o+2;i++)cout<<real_map[i][0]<<"\t";cout<<endl;
for(int i=0;i<=o+2;i++)cout<<real_map[i][1]<<"\t";cout<<endl;*/
for(int i=0;i<n;i++)
{
cout<<i<<":"<<endl;
find(i,location,g[0],-1);
}
answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |