제출 #51970

#제출 시각아이디문제언어결과실행 시간메모리
51970TadijaSebezCommuter Pass (JOI18_commuter_pass)C++11
100 / 100
1352 ms149040 KiB
#include <stdio.h> #include <vector> #include <algorithm> #include <queue> using namespace std; #define mp make_pair #define pb push_back #define ll long long const int N=100050; vector<pair<int,int> > E[N]; vector<int> go[N]; ll dist[N],sol[N][3]; const ll inf=1e18; bool ok[N]; bool mark[N]; void DFS(int u) { mark[u]=1; for(int i=0;i<go[u].size();i++) { int v=go[u][i]; if(!mark[v]) DFS(v); } } void Dijkstra1(int n, int s, int t) { int i; for(i=1;i<=n;i++) dist[i]=inf,go[i].clear(),mark[i]=0; priority_queue<pair<ll,int> > pq; dist[s]=0; pq.push(mp(0,s)); while(pq.size()) { int u=pq.top().second; ll w=-pq.top().first; pq.pop(); if(w!=dist[u]) continue; for(i=0;i<E[u].size();i++) { int v=E[u][i].first; w=E[u][i].second; if(dist[v]>dist[u]+w) { dist[v]=dist[u]+w; go[v].clear(); pq.push(mp(-dist[v],v)); } if(dist[v]==dist[u]+w) go[v].push_back(u); } } DFS(t); for(i=1;i<=n;i++) if(!mark[i]) go[i].clear(); } ll Dijkstra2(int n, int s, int t) { int i; for(i=1;i<=n;i++) sol[i][0]=sol[i][1]=sol[i][2]=inf; priority_queue<pair<ll,pair<int,int> > > pq; sol[s][0]=0; pq.push(mp(0,mp(s,0))); while(pq.size()) { int u=pq.top().second.first; int t=pq.top().second.second; ll w=-pq.top().first; pq.pop(); if(w!=sol[u][t]) continue; if(t==0 || t==2) { if(t==0 && sol[u][0]<sol[u][1]) { sol[u][1]=sol[u][0]; pq.push(mp(-sol[u][1],mp(u,1))); } for(i=0;i<E[u].size();i++) { int v=E[u][i].first; w=E[u][i].second; if(sol[v][t]>sol[u][t]+w) { sol[v][t]=sol[u][t]+w; pq.push(mp(-sol[v][t],mp(v,t))); } } } else if(t==1) { if(sol[u][1]<sol[u][2]) { sol[u][2]=sol[u][1]; pq.push(mp(-sol[u][2],mp(u,2))); } for(i=0;i<go[u].size();i++) { int v=go[u][i]; if(sol[v][t]>sol[u][t]) { sol[v][t]=sol[u][t]; pq.push(mp(-sol[v][t],mp(v,t))); } } } } return sol[t][2]; } ll min(ll a, ll b){ return a>b?b:a;} int main() { int n,m,u,v,w,i,a,b,s,t; scanf("%i %i",&n,&m); scanf("%i %i",&s,&t); scanf("%i %i",&a,&b); while(m--) scanf("%i %i %i",&u,&v,&w),E[u].pb(mp(v,w)),E[v].pb(mp(u,w)); Dijkstra1(n,t,s); ll ans=Dijkstra2(n,a,b); ans=min(ans,Dijkstra2(n,b,a)); Dijkstra1(n,t,s); ans=min(ans,Dijkstra2(n,a,b)); ans=min(ans,Dijkstra2(n,b,a)); printf("%lld\n",ans); return 0; }

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

commuter_pass.cpp: In function 'void DFS(int)':
commuter_pass.cpp:19:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<go[u].size();i++)
              ~^~~~~~~~~~~~~
commuter_pass.cpp: In function 'void Dijkstra1(int, int, int)':
commuter_pass.cpp:38:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0;i<E[u].size();i++)
           ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'long long int Dijkstra2(int, int, int)':
commuter_pass.cpp:75:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(i=0;i<E[u].size();i++)
            ~^~~~~~~~~~~~
commuter_pass.cpp:93:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(i=0;i<go[u].size();i++)
            ~^~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:109:16: warning: unused variable 'i' [-Wunused-variable]
  int n,m,u,v,w,i,a,b,s,t;
                ^
commuter_pass.cpp:110:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
commuter_pass.cpp:111:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&s,&t);
  ~~~~~^~~~~~~~~~~~~~~
commuter_pass.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&a,&b);
  ~~~~~^~~~~~~~~~~~~~~
commuter_pass.cpp:113:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  while(m--) scanf("%i %i %i",&u,&v,&w),E[u].pb(mp(v,w)),E[v].pb(mp(u,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...