제출 #540190

#제출 시각아이디문제언어결과실행 시간메모리
540190krit3379Commuter Pass (JOI18_commuter_pass)C++17
31 / 100
448 ms35116 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 struct A{ long long a,w,st,tr; bool operator<(const A& o)const{ return w>o.w; } }; vector<vector<long long>> dis(2,vector<long long>(N,1e18)),dp(3,vector<long long>(N,1e18)); vector<A> g[N]; bitset<N> in; priority_queue<A> q; void dijk(int idx,int s){ q.push({s,0}); dis[idx][s]=0; while(!q.empty()){ auto [a,w,st,tr]=q.top(); q.pop(); if(w>dis[idx][a])continue; for(auto x:g[a]){ if(w+x.w<dis[idx][x.a])q.push({x.a,w+x.w}),dis[idx][x.a]=w+x.w; } } } int main(){ int n,m,s,t,u,v,i,a,b; long long w,mi; scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v); for(i=1;i<=m;i++){ scanf("%d %d %lld",&a,&b,&w); g[a].push_back({b,w}); g[b].push_back({a,w}); } dijk(0,s); dijk(1,t); mi=dis[0][t]; for(i=1;i<=n;i++)if(dis[0][i]+dis[1][i]==mi)in[i]=true; q.push({u,0,0,0}); dp[0][u]=0; while(!q.empty()){ auto [a,w,st,tr]=q.top(); q.pop(); if(w>dp[st][a])continue; if(st==0&&in[a]&&w<dp[1][a])q.push({a,w,1,0}),dp[1][a]=w; for(auto x:g[a]){ if(st!=1&&w+x.w<dp[st][x.a])q.push({x.a,w+x.w,st,tr}),dp[st][x.a]=w+x.w; if(st==1&&w+x.w<dp[2][x.a])q.push({x.a,w+x.w,2,tr}),dp[2][x.a]=w+x.w; if(st==1&&in[x.a]&&abs(dis[0][a]-dis[0][x.a])==x.w&&w<dp[1][x.a]){ if(!tr)q.push({x.a,w,1,(dis[0][a]-dis[0][x.a]>0)?1:-1}),dp[1][x.a]=w; else if(a!=s&&a!=t&&tr==1&&dis[0][a]-dis[0][x.a]>0)q.push({x.a,w,1,1}),dp[1][x.a]=w; else if(a!=s&&a!=t&&tr==-1&&dis[0][a]-dis[0][x.a]<0)q.push({x.a,w,1,-1}),dp[1][x.a]=w; } } } printf("%lld",min({dp[0][v],dp[1][v],dp[2][v]})); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d %d %lld",&a,&b,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...