이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define ist insert
using namespace std;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
typedef long long ll;
typedef pair<ll,ll> pii;
const int N=205;
const int MOD=1000000007;//998244353
const int INF=1700000000000000000;//2147483647;
int n,m;
struct I{
int u,v,c,D,id;
} ee[50005];
vector<pii> e[N];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[N];
int dij(int s,int t){
memset(d,0x3f,sizeof(d));
d[s]=0;
pq.push({0,s});
while (pq.size()){
int v=pq.top().se,w=pq.top().fi;pq.pop();
if (d[v]<w) continue;
for (pii i:e[v]) if(d[i.fi]>w+i.se){
d[i.fi]=w+i.se;
pq.push({d[i.fi],i.fi});
}
}
return d[t];
}
inline void sol(){
cin >>n>>m;
for (int i=0;i<m;i++){
cin >>ee[i].u>>ee[i].v>>ee[i].c>>ee[i].D;
}
int ans=INF;
for (int kk=0;kk<=m;kk++){
for (int i=1;i<=n;i++) e[i].clear();
int cst=0;
for (int i=0;i<m;i++){
if (i==kk) e[ee[i].v].pb({ee[i].u,ee[i].c}),cst=ee[i].D;
else e[ee[i].u].pb({ee[i].v,ee[i].c});
}
ans=min(ans,dij(1,n)+dij(n,1)+cst);
}
cout <<ans<<'\n';
}
signed main(){
int _=1;
//cin >>_;
while (_--) sol();
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |