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,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];
set<int>s;
void cch(int x,int dis,int st){
for(int i=0;i<rv[x].size();i++){
if(rv[x][i]==st) {sz=dis+1;return;}
cch(rv[x][i],dis+1,st);
}
}
void dfs(int x,int dis,int st){
//cout<<st<<" "<<x<<" "<<dis<<" "<<k<<" "<<sz<<endl;
if(x%2==0 && abs(k-dis)%sz==0 && dis<=k)
{
res+=1-fx[x];
fx[x]=1;
}
for(int i=0;i<rv[x].size();i++){
if(rv[x][i]==st) continue;
dfs(rv[x][i],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);
}
}
Compilation message (stderr)
garden.cpp: In function 'void cch(int, int, int)':
garden.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rv[x].size();i++){
~^~~~~~~~~~~~~
garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rv[x].size();i++){
~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |