이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,M; cin >> N >> M;
vector<pair<int,int>> doges(M);
for(int i = 0;i<M;++i){
cin >> doges[i].f >> doges[i].s;
}
priority_queue<pair<ll,int>> pq; pq.push({0,1});
vector<ll> dist(M,-1); dist[1] = 0;
while(!pq.empty()){
int j = pq.top().s, cd = pq.top().f; pq.pop();
if(dist[j] != cd) continue;
for(int i = 0;i<M;++i){
if(i == j) continue;
if(doges[i].f == doges[j].f){
if(cd < dist[i] || dist[i] == -1){
dist[i] = cd;
pq.push({dist[i],i});
}
continue;
}
if((abs(doges[j].f-doges[i].f)) % doges[i].s == 0){
ll x = abs(doges[j].f-doges[i].f)/doges[i].s;
if(x+cd < dist[i] || dist[i] == -1){
dist[i] = x+cd;
pq.push({dist[i],i});
}
}
}
}
cout << dist[0] << "\n";
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |