이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const int MAX=1e6;
vector<pii> vec[MAX];
int P_,CycleLength,Min[MAX],Distance[MAX],deg[MAX];
void dfs(int node,int type,int dis)
{
if(node==P_)
{
CycleLength=dis;
return ;
}
if(type==1)
Distance[node]=dis;
if(type==2)
{
for(auto A:vec[node])
{
if(Min[node]==A.first)
dfs(A.first,A.second,dis+1);
}
return ;
}
for(auto A:vec[node])
{
if(Min[node]==A.first and deg[node]==2)
continue;
dfs(A.first,A.second,dis+1);
}
return ;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
P_=P;
int u,v,res=0;
for(int A=0;A<N;A++)
Distance[A]=-1;
for(int A=0;A<M;A++)
{
u=R[A][0];
v=R[A][1];
if(deg[u]<2)
{
++deg[u];
vec[v].pb(mp(u,deg[u]));
}
if(deg[v]<2)
{
++deg[v];
vec[u].pb(mp(v,deg[v]));
}
if(!Min[u])
Min[u]=v;
if(!Min[v])
Min[v]=u;
}
Distance[P]=0;
for(auto A:vec[P])
dfs(A.first,A.second,1);
for(int A=0;A<N;A++)
{
if(Distance[A]==-1)
continue;
else if(CycleLength==0)
res+=Distance[A]==G[0];
else if(G[0]-Distance[A]>=0 and (G[0]-Distance[A])%CycleLength==0)
res++;
}
answer(res);
///cout<<res;
return ;
}
/*signed main()
{
ios_base::sync_with_stdio(false);
int G[]={3};
int R[][2]={{1,2},{0,1},{0,3},{3,4},{4,5},{1,5}};
count_routes(6,6,0,R,1,G);
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |