#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
int a,k,n,m,q,p,v1[300005],sz,sz1,sz2,st,ch,res;
bool fx[300005];
vector<pair<int,int> >v[150005];
vector<int>rv[300005];
void cch(int x,int dis,int st){
for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
if(*it==st) {sz=dis+1;return;}
cch(*it,dis+1,st);
}
}
void dfs(int x,int dis,int st){
if(k<dis) return;
//cout<<st<<" "<<x<<" "<<dis<<" "<<k<<" "<<sz<<endl;
if(x%2==0 && abs(k-dis)%sz==0)
{
res+=(1^fx[x]);
fx[x]=1;
}
for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
if(*it==st) continue;
dfs(*it,dis+1,st);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
int n=N,m=M,p=P;
for(int i=0;i<m;i++){///grafi1
v[R[i][0]].push_back({i,R[i][1]});
v[R[i][1]].push_back({i,R[i][0]});
}
for(int i=0;i<n;i++){
sort(v[i].begin(),v[i].end());
}
for(int i=0;i<n;i++){///grafi2
if(v[i].size()==1)
{
int to=v[i][0].second;
int val=v[i][0].first;
if(v[to][0].first==val)
v1[2*i+1]=2*to+1;
else
v1[2*i+1]=2*to;
if(v[to][0].first==val)
v1[2*i]=2*to+1;
else
v1[2*i]=2*to;
}
else
{
int to=v[i][0].second;
int val=v[i][0].first;
// cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
if(v[to][0].first==val)
v1[2*i]=2*to+1;
else
v1[2*i]=2*to;
to=v[i][1].second;
val=v[i][1].first;
// cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
if(v[to][0].first==val)
v1[2*i+1]=2*to+1;
else
v1[2*i+1]=2*to;
}
}
for(int i=0;i<2*n;i++){
//cout<<i<<" "<<v1[i]<<endl;
rv[v1[i]].push_back(i);
}
sz=1000000003;cch(2*p,0,2*p);sz1=sz;
sz=1000000003;cch(2*p+1,0,2*p+1);sz2=sz;
for(int i=0; i<Q; i++)
{
k=G[i];
for(int j=0;j<2*n;j++)
fx[j]=0;
res=0;
sz=sz1;dfs(2*p,0,2*p);
sz=sz2;dfs(2*p+1,0,2*p+1);
answer(res);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11100 KB |
Output is correct |
2 |
Correct |
12 ms |
10972 KB |
Output is correct |
3 |
Correct |
12 ms |
11000 KB |
Output is correct |
4 |
Correct |
12 ms |
10952 KB |
Output is correct |
5 |
Correct |
15 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11232 KB |
Output is correct |
7 |
Correct |
12 ms |
10872 KB |
Output is correct |
8 |
Correct |
12 ms |
11000 KB |
Output is correct |
9 |
Correct |
16 ms |
11228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11100 KB |
Output is correct |
2 |
Correct |
12 ms |
10972 KB |
Output is correct |
3 |
Correct |
12 ms |
11000 KB |
Output is correct |
4 |
Correct |
12 ms |
10952 KB |
Output is correct |
5 |
Correct |
15 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11232 KB |
Output is correct |
7 |
Correct |
12 ms |
10872 KB |
Output is correct |
8 |
Correct |
12 ms |
11000 KB |
Output is correct |
9 |
Correct |
16 ms |
11228 KB |
Output is correct |
10 |
Correct |
12 ms |
11000 KB |
Output is correct |
11 |
Correct |
24 ms |
13048 KB |
Output is correct |
12 |
Correct |
45 ms |
14752 KB |
Output is correct |
13 |
Correct |
77 ms |
28536 KB |
Output is correct |
14 |
Correct |
145 ms |
23096 KB |
Output is correct |
15 |
Correct |
188 ms |
23476 KB |
Output is correct |
16 |
Correct |
151 ms |
20700 KB |
Output is correct |
17 |
Correct |
138 ms |
19748 KB |
Output is correct |
18 |
Correct |
46 ms |
14792 KB |
Output is correct |
19 |
Correct |
146 ms |
23124 KB |
Output is correct |
20 |
Correct |
177 ms |
23288 KB |
Output is correct |
21 |
Correct |
179 ms |
20628 KB |
Output is correct |
22 |
Correct |
130 ms |
19656 KB |
Output is correct |
23 |
Correct |
141 ms |
24184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11100 KB |
Output is correct |
2 |
Correct |
12 ms |
10972 KB |
Output is correct |
3 |
Correct |
12 ms |
11000 KB |
Output is correct |
4 |
Correct |
12 ms |
10952 KB |
Output is correct |
5 |
Correct |
15 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11232 KB |
Output is correct |
7 |
Correct |
12 ms |
10872 KB |
Output is correct |
8 |
Correct |
12 ms |
11000 KB |
Output is correct |
9 |
Correct |
16 ms |
11228 KB |
Output is correct |
10 |
Correct |
12 ms |
11000 KB |
Output is correct |
11 |
Correct |
24 ms |
13048 KB |
Output is correct |
12 |
Correct |
45 ms |
14752 KB |
Output is correct |
13 |
Correct |
77 ms |
28536 KB |
Output is correct |
14 |
Correct |
145 ms |
23096 KB |
Output is correct |
15 |
Correct |
188 ms |
23476 KB |
Output is correct |
16 |
Correct |
151 ms |
20700 KB |
Output is correct |
17 |
Correct |
138 ms |
19748 KB |
Output is correct |
18 |
Correct |
46 ms |
14792 KB |
Output is correct |
19 |
Correct |
146 ms |
23124 KB |
Output is correct |
20 |
Correct |
177 ms |
23288 KB |
Output is correct |
21 |
Correct |
179 ms |
20628 KB |
Output is correct |
22 |
Correct |
130 ms |
19656 KB |
Output is correct |
23 |
Correct |
141 ms |
24184 KB |
Output is correct |
24 |
Correct |
14 ms |
10872 KB |
Output is correct |
25 |
Correct |
171 ms |
13176 KB |
Output is correct |
26 |
Correct |
206 ms |
14808 KB |
Output is correct |
27 |
Execution timed out |
5076 ms |
28540 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |