제출 #745535

#제출 시각아이디문제언어결과실행 시간메모리
745535PacybwoahOlympic Bus (JOI20_ho_t4)C++14
11 / 100
75 ms3800 KiB
#include<iostream> #include<utility> #include<vector> #include<algorithm> #define ll long long using namespace std; int main(){ int n,m; cin>>n>>m; vector<vector<pair<ll,pair<ll,ll>>>> graph(n+1); int a,b,c,d; vector<vector<ll>> dist(n+1,vector<ll>(n+1,1e18)); for(int i=1;i<=n;i++) dist[i][i]=0; for(int i=0;i<m;i++){ cin>>a>>b>>c>>d; graph[a].push_back(make_pair(b,make_pair(c,d))); dist[a][b]=min(dist[a][b],1ll*c); } for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]); } } } ll ans=dist[1][n]+dist[n][1]; for(int i=1;i<=n;i++){ for(auto x:graph[i]){ ans=min(ans,min(dist[1][n],dist[1][x.first]+x.second.first+dist[i][n])+min(dist[n][1],dist[n][x.first]+x.second.first+dist[i][1])+x.second.second); } } if(ans>=1e18) cout<<-1; else cout<<ans; //for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cout<<i<<" "<<j<<" "<<dist[i][j]<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...