# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
417547 | APROHACK | Robot (JOI21_ho_t4) | C++14 | 63 ms | 11112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define ll long long
// Mira las constantes
// Estudia las propiedades
// Keep calm
ll n, m;
vector<pair<pair<int, ll>, int> >g[100001];
ll dijkstra(){
priority_queue<pair<ll, int> >pq;
pq.push({0, 1});
ll u, v,ci;
ll D[100001];
for(int i = 0 ; i <= 100000 ; i++)D[i]=LLONG_MAX;
while(pq.size()){
u=pq.top().S;
ci=(pq.top().F)*-1;
pq.pop();
bool isval=true;
for(int i = 0 ; i < g[u].size() ; i++){
if(i>0&&g[u][i-1].F.F==g[u][i].F.F)isval=false;
if(i+1<g[u].size()&&g[u][i+1].F.F==g[u][i].F.F)isval=false;
if(isval){
if(D[g[u][i].S]>ci){
D[g[u][i].S]=ci;
pq.push({-1*(ci), g[u][i].S});
}else{
continue;
}
}else{
if(D[g[u][i].S]>ci+g[u][i].F.S){
D[g[u][i].S]=ci+g[u][i].F.S;
pq.push({-1*(ci+g[u][i].F.S), g[u][i].S});
}else{
continue;
}
}
}
}
return D[n];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
cin>>n>>m;
ll a, b, c, p;
for(int i = 0 ; i < m ; i++){
cin>>a>>b>>c>>p;
g[a].PB({{c, p}, b});
g[b].PB({{c, p}, a});
}
for(int i = 1 ; i <= n; i++){
sort(g[i].begin(), g[i].end());
}
ll res=dijkstra();
if(res==LLONG_MAX){
cout<<"-1\n";
}else{
cout<<res;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |