제출 #718700

#제출 시각아이디문제언어결과실행 시간메모리
718700sofija6Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
862 ms46860 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INF=LONG_LONG_MAX; ll m, n, s, t, u, v; vector<pair<ll, ll> >graff[200010]; vector<ll>dag[200010]; bool check1[200010], check2[200010]; ll distu[200010], distv[200010], dists[200010], distt[200010]; ll res=INF; set<pair<ll,ll> > grane; void dijkstra(ll cvor, ll *dist) { for(int i=0; i<100010; i++) { check1[i]=false; dist[i]=INF; } priority_queue<pair<ll, ll> >ord; dist[cvor]=0; ord.push({0, cvor}); while(!ord.empty()) { int cv=ord.top().second; ord.pop(); if(check1[cv])continue; check1[cv]=true; for(int j=0; j<graff[cv].size(); j++) { ll pp=graff[cv][j].first; dist[pp]=min(dist[pp], dist[cv]+graff[cv][j].second); if(!check1[pp])ord.push({-dist[pp], pp}); } } } void dfs1(ll prosli, ll cvor) { if(dists[cvor]+distt[cvor]!=dists[t])return; if(dists[cvor]-dists[prosli]<0)return; dag[prosli].push_back(cvor); if(cvor==t)return; for(int i=0; i<graff[cvor].size(); i++) { if (dists[cvor]+graff[cvor][i].second+distt[graff[cvor][i].first]==dists[t] && !grane.count({cvor, graff[cvor][i].first})) { grane.insert({cvor, graff[cvor][i].first}); dfs1(cvor, graff[cvor][i].first); } } return; } void dfs2(ll cvor, ll minv, ll minu) { minv=min(minv, distv[cvor]); minu=min(minu, distu[cvor]); res=min(res, minv+minu); if(cvor==t)return; for(int i=0; i<dag[cvor].size(); i++) { if (!grane.count({cvor,dag[cvor][i]}) || minv>distv[dag[cvor][i]] || minu>distu[dag[cvor][i]]) { grane.insert({cvor,dag[cvor][i]}); dfs2(dag[cvor][i], minv, minu); } } return; } void solve() { priority_queue<pair<ll,ll> > q; ll U[100010],V[100010]; for (ll i=1;i<=n;i++) { U[i]=INF; V[i]=INF; } U[s]=distu[s]; V[s]=distv[s]; q.push({-U[s],s}); while (!q.empty()) { ll t=q.top().second,d=abs(q.top().first); q.pop(); if (U[t]!=d) continue; res=min(res,U[t]+V[t]); for (auto next : dag[t]) { ll i=next; if (U[i]==INF) { U[i]=distu[i]; V[i]=distv[i]; q.push({-U[i],i}); } if (U[t]<U[i]) { U[i]=U[t]; V[i]=min(distv[i],V[t]); q.push({-U[i],i}); } else if (U[t]==U[i]) { if (V[i]<=V[t]) V[i]=distv[i]; else { V[i]=V[t]; q.push({-U[i],i}); } } } } for (ll i=1;i<=n;i++) { U[i]=INF; V[i]=INF; } U[s]=distu[s]; V[s]=distv[s]; q.push({-V[s],s}); while (!q.empty()) { ll t=q.top().second,d=abs(q.top().first); q.pop(); if (V[t]!=d) continue; res=min(res,U[t]+V[t]); for (auto next : dag[t]) { ll i=next; if (V[i]==INF) { V[i]=distv[i]; U[i]=distu[i]; q.push({-V[i],i}); } if (V[t]<V[i]) { V[i]=V[t]; U[i]=min(distu[i],U[t]); q.push({-V[i],i}); } else if (V[t]==V[i]) { if (U[i]<=U[t]) U[i]=distu[i]; else { U[i]=U[t]; q.push({-V[i],i}); } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin>>n>>m; cin>>s>>t; cin>>u>>v; ll a, b, c; for(int i=0; i<m; i++) { cin>>a>>b>>c; graff[a].push_back({b, c}); graff[b].push_back({a, c}); } dijkstra(u, distu); dijkstra(v, distv); dijkstra(s, dists); dijkstra(t, distt); dists[0]=0; dfs1(0, s); ///dfs2(s, INF, INF); solve(); cout<<min(res, distv[u]); return 0; }

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

commuter_pass.cpp: In function 'void dijkstra(ll, ll*)':
commuter_pass.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int j=0; j<graff[cv].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void dfs1(ll, ll)':
commuter_pass.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<graff[cvor].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void dfs2(ll, ll, ll)':
commuter_pass.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0; i<dag[cvor].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...