이 제출은 이전 버전의 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<pii>adj[mxn],radj[mxn];
int dij(int st,int ed){
vector<int>dis(mxn);
for(int i=0;i<mxn;i++)dis[i]=1e18;
dis[st]=0;
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({0,st});
while(sz(pq)){
auto [d,v]=pq.top();
pq.pop();
if(dis[v]<d)continue;
//cout<<v<<' ';
for(auto [u,dd]:adj[v]){
if(dis[v]+dd<dis[u]){
dis[u]=dis[v]+dd;
pq.push({dis[u],u});
}
}
}
//for(int i=1;i<=8;i++)cout<<dis[i]<<' ';
//cout<<'\n';
return dis[ed];
}
int rdij(int st,int ed){
vector<int>dis(mxn);
for(int i=0;i<mxn;i++)dis[i]=1e18;
dis[st]=0;
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({0,st});
while(sz(pq)){
auto [d,v]=pq.top();
pq.pop();
if(dis[v]<d)continue;
//cout<<v<<' ';
for(auto [u,dd]:radj[v]){
if(dis[v]+dd<dis[u]){
dis[u]=dis[v]+dd;
pq.push({dis[u],u});
}
}
}
//for(int i=1;i<=8;i++)cout<<dis[i]<<' ';
//cout<<'\n';
return dis[ed];
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
setio();
int n,m;
cin>>n>>m;
for(int i=0;i<m;i+=2){
int a,b,c,d;
cin>>a>>b>>c>>d;
int d2;
cin>>a>>b>>c>>d2;
d=min(d,d2);
e.pb({a,b,c,d});
adj[a].pb({b,c});
adj[b].pb({a+n,d+c});
adj[a+n].pb({b+n,c});
//adj[a].pb({b,c});
radj[b+n].pb({a,d+c});
//radj[a+n].pb({b,c});
radj[a+n].pb({b+n,c});
radj[a].pb({b,c});
}
int ans=dij(n+1,n+n)+rdij(n,1);
//cout<<ans<<'\n';
ans=min(ans,dij(1,2*n)+rdij(n,1));
//cout<<ans<<'\n';
ans=min(ans,rdij(2*n,1)+dij(1,n));
//ans=min(ans,dij(1,2*n)+dij(2*n,1));
if(ans>=1e9){
cout<<-1<<'\n';
return 0;
}
cout<<ans<<'\n';
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
ho_t4.cpp: In function 'long long int dij(long long int, long long int)':
ho_t4.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | auto [d,v]=pq.top();
| ^
ho_t4.cpp:34:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for(auto [u,dd]:adj[v]){
| ^
ho_t4.cpp: In function 'long long int rdij(long long int, long long int)':
ho_t4.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | auto [d,v]=pq.top();
| ^
ho_t4.cpp:56:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [u,dd]:radj[v]){
| ^
# | 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... |