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;
int aa , m , one , two , col;
long long p , ans[200001] , an[200001] , choto[200001] , chek[200001] , uttor;
vector<pair<pair<int , long long> , int>> arr[200001]; //first e col , then price , then node
priority_queue<pair<long long , int> , vector<pair<long long , int>> , greater<pair<long long , int>>> pq;
int main() {
cin >> aa >> m;
for( int z = 0; z < m; z++ ) {
cin >> one >> two >> col >> p;
arr[one].push_back({{col , p} , two});
arr[two].push_back({{col , p} , one});
}
for( int z = 1; z <= aa; z++ ) {
sort( arr[z].begin() , arr[z].end() );
}
ans[1] = 1;
pq.push({1 , 1});
while( !pq.empty() ) {
if( chek[pq.top().second] == 0 ) {
chek[pq.top().second] = 1;
one = pq.top().second;
ans[one] = pq.top().first;
two = arr[one].size();
for( int z = 0; z < two; z++ ) {
an[arr[one][z].first.first] += arr[one][z].first.second;
if(choto[arr[one][z].first.first] == 0 ) choto[arr[one][z].first.first] = ans[one];
if( ans[arr[one][z].second] != 0 ) {
choto[arr[one][z].first.first] = min( ans[arr[one][z].second] , choto[arr[one][z].first.first] );
}
}
for( int z = 0; z < two; z++ ) {
if( chek[arr[one][z].second] == 0 ) {
uttor = min( (min(arr[one][z].first.second , an[arr[one][z].first.first] - arr[one][z].first.second) + ans[one] ) , (an[arr[one][z].first.first] - arr[one][z].first.second) + choto[arr[one][z].first.first] );
pq.push({uttor , arr[one][z].second});
}
}
for( int z = 0; z < two; z++ ) {
an[arr[one][z].first.first] = 0;
choto[arr[one][z].first.first] = 0;
}
}
else pq.pop();
}
cout << ans[aa] - 1;
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... |