제출 #702056

#제출 시각아이디문제언어결과실행 시간메모리
702056huomark1001Olympic Bus (JOI20_ho_t4)C++17
0 / 100
1085 ms3844 KiB
#include<bits/stdc++.h> #include<random> using namespace std; template<typename T> void _do(T x){cerr<<x<<"\n";} template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);} #define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__); #define float double #define ss(n) fixed<<setprecision(n) #define ll long long #define int ll #define IO ios::sync_with_stdio(false);cin.tie(0); #define ld long double #define pb push_back #define pii pair<int,int> #define rep(i,a) for(int i=1;i<=a;i++) #define rep0(i,a) for(int i=0;i<a;i++) #define F first #define S second #define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end()))); #define unisort(a) sort(a.begin(),a.end()); uni(a); ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);} const ld pi=3.14159265358979323846264338327950288419716939931; const int lar=3e18; const int mol1=1e9+7; const int mol2=998244353; const int MX=3e5; vector<pair<pair<int,int>,int>>node[205]; void solve() { int n,m; cin>>n>>m; int u[m+1],v[m+1],c[m+1],d[m+1]; rep(i,m){ cin>>u[i]>>v[i]>>c[i]>>d[i]; node[u[i]].pb({{v[i],c[i]},i}); } int ans=lar; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>>now; rep(i,m){ int x=u[i],y=v[i]; node[y].pb({{x,c[i]+d[i]},m+1}); int dp1[n+1],dp2[n+1]; rep(j,n) dp1[j]=lar,dp2[j]=lar; dp1[1]=0,dp2[n]=0; now.push({0,1}); while(now.size()){ int v1=now.top().S;int dd=now.top().F;now.pop(); if(dp1[v1]!=dd) continue; for(pair<pair<int,int>,int> g:node[v1]){ if(g.S==i) continue; if(dp1[g.F.F]>dp1[v1]+g.F.S){ dp1[g.F.F]=dp1[v1]+g.F.S; now.push({dp1[g.F.F],g.F.F}); } } } now.push({0,n}); while(now.size()){ int v1=now.top().S;int dd=now.top().F;now.pop(); if(dp2[v1]!=dd) continue; for(pair<pair<int,int>,int> g:node[v1]){ if(g.S==i) continue; if(dp2[g.F.F]>dp2[v1]+g.F.S){ dp2[g.F.F]=dp2[v1]+g.F.S; now.push({dp2[g.F.F],g.F.F}); } } } node[y].pop_back(); ans=min(ans,dp1[n]+dp2[1]); } if(ans>=lar) cout<<-1<<"\n"; else cout<<ans<<"\n"; } signed main() { IO solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...