제출 #853303

#제출 시각아이디문제언어결과실행 시간메모리
853303Zero_OPCommuter Pass (JOI18_commuter_pass)C++14
24 / 100
202 ms22284 KiB
#include<bits/stdc++.h> using namespace std; #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) #define len(x) (int)(x).size() #define BIT(x, i) ((x)>>(i)&1) #define MASK(x) (1LL<<(x)) typedef long long ll; typedef long double ld; typedef unsigned long long ull; template<class T> bool maximize(T& a, const T& b){ if(a<b) return a=b, true; return false; } template<class T> bool minimize(T& a, const T& b){ if(a>b) return a=b, true; return false; } const int N=1e5+5; int n, m, s, t, U, V; vector<pair<int, int>> g[N]; vector<int> rev[N]; vector<ll> dijkstra(int st){ vector<ll> d(n+1, -1); d[st]=0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.push({0, st}); while(!pq.empty()){ ll cost; int u; tie(cost, u)=pq.top(); pq.pop(); if(cost!=d[u]) continue; for(int i=0; i<g[u].size(); ++i){ int v=g[u][i].first, w=g[u][i].second; if(d[v]==-1 or d[v]>(d[u]+w)){ d[v]=d[u]+w; pq.push({d[v], v}); } } } return d; } void Zero_OP(){ cin>>n>>m>>s>>t>>U>>V; if(n<=300){ ll d[n+1][n+1]; memset(d, 0x3f, sizeof(d)); for(int i=1; i<=n; ++i) d[i][i]=0; for(int i=1; i<=m; ++i){ int u, v; ll w; cin>>u>>v>>w; minimize(d[u][v], w); minimize(d[v][u], w); } for(int k=1; k<=n; ++k){ for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ minimize(d[i][j], d[i][k]+d[k][j]); } } } ll ans=d[U][V]; for(int i=1; i<=n; ++i){ for(int j=1; j<=n; ++j){ if(d[s][i]+d[i][j]+d[j][t]==d[s][t]){ minimize(ans, min(d[U][i]+d[j][V], d[V][i]+d[j][U])); } } } cout<<ans; } else { while(m--){ int u, v, w; cin>>u>>v>>w; g[u].push_back({v, w}); g[v].push_back({u, w}); } vector<ll> d_u=dijkstra(U), d_v=dijkstra(V), d_t=dijkstra(t); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; vector<ll> d_s(n+1, -1); d_s[s]=0; pq.push({0, s}); while(!pq.empty()){ ll cost; int u; tie(cost, u)=pq.top(); pq.pop(); if(d_s[u]!=cost) continue; for(int i=0; i<g[u].size(); ++i){ int v=g[u][i].first, w=g[u][i].second; if(d_s[v]==-1 or (d_s[v]>d_s[u]+w)){ d_s[v]=d_s[u]+w; rev[v].clear(); rev[v].push_back(u); pq.push({d_s[v], v}); } else if(d_s[u]+w==d_s[v]) rev[v].push_back(u); } } ll ans=d_u[V]; vector<ll> d(n+1, -1); d[t]=d_u[t]; pq.push({d[t], t}); while(!pq.empty()){ ll cost; int u; tie(cost, u)=pq.top(); pq.pop(); if(cost!=d[u]) continue; minimize(ans, d[u]+d_v[u]); for(int i=0; i<rev[u].size(); ++i){ int v=rev[u][i]; if(d[v]==-1 or d[v]>min(d[u], d_u[v])){ d[v]=min(d[u], d_u[v]); pq.push({d[v], v}); } } } d.resize(n+1, -1); d[t]=d_v[t]; pq.push({d[t], t}); while(!pq.empty()){ ll cost; int u; tie(cost, u)=pq.top(); pq.pop(); if(cost!=d[u]) continue; for(int i=0; i<rev[u].size(); ++i){ int v=rev[u][i]; if(d[v]==-1 or d[v]>min(d[u], d_v[v])){ d[v]=min(d[u], d_v[v]); pq.push({d[v], v}); } } } cout<<ans; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define task "COMPUTER_PASS" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int TC=1; //cin>>TC; while(TC--) Zero_OP(); return 0; }

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

commuter_pass.cpp: In function 'std::vector<long long int> dijkstra(int)':
commuter_pass.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0; i<g[u].size(); ++i){
      |                  ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'void Zero_OP()':
commuter_pass.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |       for(int i=0; i<g[u].size(); ++i){
      |                    ~^~~~~~~~~~~~
commuter_pass.cpp:120:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |       for(int i=0; i<rev[u].size(); ++i){
      |                    ~^~~~~~~~~~~~~~
commuter_pass.cpp:138:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |       for(int i=0; i<rev[u].size(); ++i){
      |                    ~^~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:157:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  157 |     freopen(task".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:158:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  158 |     freopen(task".OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...