#include "garden.h"
#include "gardenlib.h"
#include <iostream>
#include <cstdlib>
#define maxn 100005
using namespace std;
int map[4*maxn][3],o;
int real_map[4*maxn][3];
int sort[maxn][3];
int ans=0;
int t[4*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!=-1)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<4*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<n;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++)cout<<sort[j][2]<<" ";cout<<endl;
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 j=1;j<=q;j++)
{
ans=0;
for(int i=0;i<n;i++)
{
// cout<<i<<":"<<endl;
find(i,location,g[j-1],-1);
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11384 KB |
Output is correct |
2 |
Correct |
12 ms |
11256 KB |
Output is correct |
3 |
Correct |
11 ms |
11256 KB |
Output is correct |
4 |
Correct |
11 ms |
11256 KB |
Output is correct |
5 |
Correct |
11 ms |
11256 KB |
Output is correct |
6 |
Correct |
12 ms |
11260 KB |
Output is correct |
7 |
Correct |
11 ms |
11316 KB |
Output is correct |
8 |
Correct |
12 ms |
11384 KB |
Output is correct |
9 |
Correct |
14 ms |
11396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11384 KB |
Output is correct |
2 |
Correct |
12 ms |
11256 KB |
Output is correct |
3 |
Correct |
11 ms |
11256 KB |
Output is correct |
4 |
Correct |
11 ms |
11256 KB |
Output is correct |
5 |
Correct |
11 ms |
11256 KB |
Output is correct |
6 |
Correct |
12 ms |
11260 KB |
Output is correct |
7 |
Correct |
11 ms |
11316 KB |
Output is correct |
8 |
Correct |
12 ms |
11384 KB |
Output is correct |
9 |
Correct |
14 ms |
11396 KB |
Output is correct |
10 |
Correct |
17 ms |
11256 KB |
Output is correct |
11 |
Execution timed out |
5004 ms |
11472 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11384 KB |
Output is correct |
2 |
Correct |
12 ms |
11256 KB |
Output is correct |
3 |
Correct |
11 ms |
11256 KB |
Output is correct |
4 |
Correct |
11 ms |
11256 KB |
Output is correct |
5 |
Correct |
11 ms |
11256 KB |
Output is correct |
6 |
Correct |
12 ms |
11260 KB |
Output is correct |
7 |
Correct |
11 ms |
11316 KB |
Output is correct |
8 |
Correct |
12 ms |
11384 KB |
Output is correct |
9 |
Correct |
14 ms |
11396 KB |
Output is correct |
10 |
Correct |
17 ms |
11256 KB |
Output is correct |
11 |
Execution timed out |
5004 ms |
11472 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |