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>
#define F first
#define S second
#define MAX 100005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
ll m,n,ans=oo;
vll pass[MAX],node[MAX];
vector<pair<pll,pll>> v[MAX];
ll distra(ll x,ll y){
priority_queue<pair<ll,pll>> q;
q.push({0,{x,-1}});
while(!q.empty()){
pair<ll,pll> u=q.top();q.pop();
// if(u.S.S>=0)cout<<u.S.F<<" "<<v[u.S.F][u.S.S].F.F<<": "<<pass[u.S.F][u.S.S]<<" "<<-u.F<<"\n";
//else cout<<u.S.F<<"-1 :0 "<<-u.F<<"\n";
if(u.S.S>=0 && pass[u.S.F][u.S.S]!=0)continue;
if(u.S.S>=0)pass[u.S.F][u.S.S]=1;
if(u.S.F==y)return -u.F;
ll c=0;
for(auto w : v[u.S.F]){
if(u.S.S==c){c++;continue;}
if(pass[w.F.F][node[u.S.F][c]]!=0){c++;continue;}
// cout<<" "<<w.F.F<<" "<<v[w.F.F][node[u.S.F][c]].F.F<<" ";
if(u.S.S>=0 && v[u.S.F][u.S.S].F.S==w.F.S){
q.push({u.F-min(w.S.F,w.S.S-w.S.F-v[u.S.F][u.S.S].S.F),{w.F.F,node[u.S.F][c]}});
cout<<-u.F+min(w.S.F,w.S.S-w.S.F-v[u.S.F][u.S.S].S.F)<<"\n";
}
else {
q.push({u.F-min(w.S.F,w.S.S-w.S.F),{w.F.F,node[u.S.F][c]}});
// cout<<-u.F+min(w.S.F,w.S.S-w.S.F)<<".\n";
}
c++;
}
}
return -1;
}
int main(){
cin>>n>>m;ll a1,a2,a3,a4;
for(int i=0;i<m;i++){
cin>>a1>>a2>>a3>>a4;
v[a1].push_back({{a2,a3},{a4,0}});
v[a2].push_back({{a1,a3},{a4,0}});
node[a1].push_back(v[a2].size()-1);
node[a2].push_back(v[a1].size()-1);
}
for(int i=1;i<=n;i++){
pass[i].assign(v[i].size()+5,0);
map<ll,ll> mp;
for(auto w : v[i]){
mp[w.F.S]+=w.S.F;
}
for(int j=0;j<v[i].size();j++){
v[i][j].S.S=mp[v[i][j].F.S];
}
}
cout<<distra(1,n);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |