이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "garden.h"
#include "gardenlib.h"
#include <vector>
#include <queue>
#include <cstdio>
const int INF=1e9+7;
static std::vector<int> adj[150005];
static int to[300005];
static std::vector<int> from[300005];
static int dist[2][300005];
static void bfs(int start,int* dist){
std::queue<int> q;
q.push(start);
while(!q.empty()){
int node=q.front();
q.pop();
for(int child:from[node]){
if(!dist[child]){
dist[child]=dist[node]+1;
q.push(child);
}
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for(int i=0;i<M;i++){
adj[R[i][0]].push_back(R[i][1]);
adj[R[i][1]].push_back(R[i][0]);
}
for(int i=0;i<N;i++){
to[i<<1]=(adj[i][0]<<1)|(i==adj[adj[i][0]][0]);
if(adj[i].size()>1){
to[i<<1|1]=(adj[i][1]<<1)|(i==adj[adj[i][1]][0]);
}else{
to[i<<1|1]=to[i<<1];
}
}
for(int i=0;i<N*2;i++){
from[to[i]].push_back(i);
}
bfs(P<<1,dist[0]);
bfs(P<<1|1,dist[1]);
int cycle[2];
cycle[0]=dist[0][P<<1]?dist[0][P<<1]:INF;
cycle[1]=dist[1][P<<1|1]?dist[1][P<<1|1]:INF;
for(int q=0; q<Q; q++){
int K=G[q];
int ans=0;
for(int i=0;i<N*2;i+=2){
if(dist[0][i]) ans+=(K>=dist[0][i]&&(K-dist[0][i])%cycle[0]==0);
if(dist[1][i]) ans+=(K>=dist[1][i]&&(K-dist[1][i])%cycle[1]==0);
}
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... |