이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"garden.h"
#include"gardenlib.h"
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int n; // num nodes
int m; // num edges
vector<vector<int>>nodes; // lowest node and second lowest node
vector<int>nxt;
void add_conn(int node,int dest){
if(nodes[node][0]==-1){
nodes[node]={dest,dest};
}else if(nodes[node][0]==nodes[node][1]){
nodes[node][1]=dest;
}
}
void count_routes(int N,int M,int P,int R[][2],int Q,int G[]){
n=N;
m=M;
nodes=vector<vector<int>>(n,{-1,-1});
nxt.resize(2*n);
for(int i=0;i<m;i++){
add_conn(R[i][0],R[i][1]);
add_conn(R[i][1],R[i][0]);
}
for(int i=0;i<2*n;i++){
nxt[i]=2*nodes[i/2][i%2];
if(nodes[nxt[i]/2][0]==i/2&&nodes[nxt[i]/2][1]!=-1)
nxt[i]++;
}
for(int i=0;i<Q;i++){
int res=0;
for(int j=0;j<n;j++){
int curr=2*j;
for(int k=0;k<G[i];k++)
curr=nxt[curr];
if(curr/2==P)
res++;
}
answer(res);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |