이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;
typedef pair< lo,PIII > PIIII;
typedef pair< lo,PIIII > PIIIII;
typedef pair< lo,PIIIII > PIIIIII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define int long long
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 203;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,val[li],vis[li][1005][4][4],mn,ans=inf,d[li];
string s;
vector<PIIII> v[li];
//~ inline void sp2(){
//~ priority_queue<PIIIII> pq;
//~ pq.push({0,{n,{0,{0,0}}}});
//~ FOR vis[i][0]=0;
//~ FOR vis[i][1]=0;
//~ mn=inf;
//~ while(pq.size()){
//~ int co=-pq.top().fi;
//~ int node=pq.top().se.fi;
//~ int hak=pq.top().se.se.fi;
//~ int xx=pq.top().se.se.se.fi;
//~ int yy=pq.top().se.se.se.se;
//~ pq.pop();
//~ if(vis[node][hak])continue;
//~ vis[node][hak]=1;
//~ if(node==1)mn=min(mn,co);
//~ for(int i=0;i<(int)v[node].size();i++){
//~ int go=v[node][i].fi;
//~ if(node==xx && go==yy)continue;
//~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}});
//~ else{
//~ if(hak)continue;
//~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}});
//~ }
//~ }
//~ }
//~ }
//~ inline void sp3(int xxx,int yyy){
//~ priority_queue<PIIIII> pq;
//~ pq.push({0,{n,{1,{xxx,yyy}}}});
//~ FOR vis[i][0]=0;
//~ FOR vis[i][1]=0;
//~ mn=inf;
//~ while(pq.size()){
//~ int co=-pq.top().fi;
//~ int node=pq.top().se.fi;
//~ int hak=pq.top().se.se.fi;
//~ int xx=pq.top().se.se.se.fi;
//~ int yy=pq.top().se.se.se.se;
//~ pq.pop();
//~ if(vis[node][hak])continue;
//~ vis[node][hak]=1;
//~ if(node==1)mn=min(mn,co);
//~ cout<<xx<<" : : "<<yy<<endl;
//~ for(int i=0;i<(int)v[node].size();i++){
//~ int go=v[node][i].fi;
//~ if(node==xx && go==yy)continue;
//~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}});
//~ else{
//~ if(hak)continue;
//~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}});
//~ }
//~ }
//~ }
//~ }
inline void sp(){
priority_queue<PIIIII> pq;
pq.push({0,{1,{0,{0,0}}}});
//~ int val1=-1,val2=-1;
//~ int stx=0,sty=0;
ans=inf;
while(pq.size()){
int co=-pq.top().fi;
int node=pq.top().se.fi;
int hak=pq.top().se.se.fi;
int xx=pq.top().se.se.se.fi;
//~ int yy=pq.top().se.se.se.se.fi;
int gel=pq.top().se.se.se.se;
pq.pop();
//~ cout<<node<<" : : "<<gel<<" : : "<<xx<<" : : "<<yy<<endl;
if(vis[node][xx][hak][gel])continue;
if(gel==1 && node==1)ans=min(ans,co);
vis[node][xx][hak][gel]=1;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==0)continue;
if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==1){
pq.push({-co-v[node][i].se.fi+d[v[node][i].se.se.se],{go,{hak,{xx,(node==n?1:gel)}}}});
continue;
}
//~ if(node==yy && go==xx){
//~ pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,{yy,(node==n?1:gel)}}}}});
//~ continue;
//~ }
if(v[node][i].se.se.fi==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,(node==n?1:gel)}}}});
else{
if(hak)continue;
pq.push({-co-v[node][i].se.fi,{go,{1,{v[node][i].se.se.se,(node==n?1:gel)}}}});
}
}
}
if(ans>=inf)ans=-1;
printf("%lld\n",ans);
}
main(void){
scanf("%lld %lld",&n,&m);
for(int i=1;i<=m;i++){
int x,y,z;
scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]);
v[x].pb({y,{z,{0,i}}});
v[y].pb({x,{z+d[i],{1,i}}});
}
sp();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t4.cpp:131:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:132:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n,&m);
~~~~~^~~~~~~~~~~~~~~~~~~
ho_t4.cpp:135:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld",&x,&y,&z,&d[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... |