이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define pb push_back
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
struct edge{
int a,b,c,d;
};
const int mxn=405;
vector<edge>e;
vector<int>temp;
pii w[mxn][mxn];
pii w2[mxn][mxn];
int id[mxn];
vector<bool>check(50005);
vector<int> dij(int st,int n,bool tf){
vector<int>dis(mxn);
for(int i=0;i<mxn;i++)dis[i]=1e15;
dis[st]=0;
if(tf){
for(int i=1;i<=n;i++){
id[i]=-1;
}
}
vector<bool>used(n+1,0);
for(int i=1;i<=n;i++){
int t=-1;
for(int j=1;j<=n;j++){
if(used[j])continue;
if(t==-1 or dis[j]<dis[t]){
t=j;
}
}
used[t]=1;
for(int j=1;j<=n;j++){
if(dis[t]+w[t][j].F<dis[j]){
dis[j]=dis[t]+w[t][j].F;
if(!tf)continue;
if(id[j]!=-1){
check[id[j]]=0;
continue;
}
id[j]=w[t][j].S;
check[id[j]]=1;
}
}
}
return dis;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
setio();
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
w[i][j]={1e15,1e15};
w2[i][j]={1e15,1e15};
}
}
for(int i=0;i<m;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
e.pb({a,b,c,d});
if(c<w[a][b].F or (c==w[a][b].F and d<e[w[a][b].S].d)){
w2[a][b]=w[a][b];
w[a][b]={c,i};
}
else if(c<w2[a][b].F or (c==w2[a][b].F and d<e[w2[a][b].S].d)){
w2[a][b]={c,i};
}
}
vector<int>dd=dij(1,n,1);
vector<int>rd=dij(n,n,1);
int ans=dd[n]+rd[1];
for(int i=0;i<m;i++){
//cout<<check[i]<<'\n';
auto [a,b,c,d]=e[i];
if(check[i]){
auto x=w[a][b];
if(w[a][b].S==i){
if(w2[a][b]!=make_pair((int)1e15,(int)1e15)){
w[a][b]=w2[a][b];
}
}
auto y=w[b][a];
w[b][a].F=min(w[b][a].F,c+d);
ans=min(ans,dij(1,n,0)[n]+dij(n,n,0)[1]);
w[a][b]=x;
w[b][a]=y;
}
else{
ans=min(ans,min(dd[b]+c+d+rd[a],dd[n])+min(rd[1],rd[b]+c+d+dd[a]));
}
//cout<<ans<<'\n';
}
if(ans>=1e15){
cout<<-1<<'\n';
return 0;
}
cout<<ans<<'\n';
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:90:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
90 | auto [a,b,c,d]=e[i];
| ^
# | 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... |