이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAX 31000
typedef std::pair<int,int> pii; ///Skyscraper .first, level .second
std::map<pii,std::vector<pii>> con;
typedef std::pair<pii,int> ppi;
int main()
{
std::map<pii,bool> visitou;
int N,M;
std::cin>>N>>M;
bool cachorro[N]={};
std::vector<int> poder[N];
int ha[M],hb[M];
for(int i=0;i!=M;++i){
int a,b;
std::cin>>a>>b;
cachorro[a]=true;
poder[a].push_back(b);
ha[i]=a;
hb[i]=b;
}
pii origem = {ha[0],hb[0]};
pii fim = {ha[1],hb[1]};
std::deque<ppi> deque;
deque.push_back({origem,0});
while(deque.size()){
auto ___ = deque.front();
auto __ = ___.first;
deque.pop_front();
if(__.first<0||__.first>=N)continue;
if(visitou.find(__)!=visitou.end())continue;
visitou[__]=true;
if(__==fim){
std::cout<<___.second<<"\n";
return 0;
}
deque.push_back({{__.first+__.second,__.second},___.second+1});
deque.push_back({{__.first-__.second,__.second},___.second+1});
if(cachorro[__.first]){
cachorro[__.first]=false;
for(auto&x:poder[__.first])
deque.push_front({{__.first,x},___.second});
}
}
std::cout<<"-1\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |