Submission #853298

#TimeUsernameProblemLanguageResultExecution timeMemory
853298Zero_OPCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
188 ms18880 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; struct edge{ int u, v, w; } e[N*2]; struct item{ int v, w, id; }; int n, m, s, t, U, V; vector<item> g[N]; bool in_shortest_path[N*2]; 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(d[u]!=cost) continue; for(int i=0; i<g[u].size(); ++i){ int v=g[u][i].v, w=g[u][i].w; if(d[v]==-1 or (d[v]>(d[u]+w))){ d[v]=d[u]+w; pq.push({d[v], v}); } } } return d; } ll modify_dijkstra(int st, int ed){ 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].v, w=(in_shortest_path[g[u][i].id]?0:g[u][i].w); if(d[v]==-1 or (d[v]>(d[u]+w))){ d[v]=d[u]+w; pq.push({d[v], v}); } } } return d[ed]; } void Zero_OP(){ cin>>n>>m>>s>>t>>U>>V; for(int i=1; i<=m; ++i){ int u, v, c; cin>>u>>v>>c; g[u].push_back({v, c, i}); g[v].push_back({u, c, i}); e[i]={u, v, c}; } if(n<=300){ ll d[n+1][n+1]; memset(d, 0x3f, sizeof(d)); for(int i=1; i<=m; ++i){ minimize(d[e[i].u][e[i].v], (ll)e[i].w); minimize(d[e[i].v][e[i].u], (ll)e[i].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 { vector<ll> d_s=dijkstra(s), d_t=dijkstra(t); for(int i=1; i<=m; ++i){ int u=e[i].u, v=e[i].v, w=e[i].w; if(d_s[u]+w+d_t[v]==d_s[t] or d_s[v]+w+d_t[u]==d_s[t]){ in_shortest_path[i]=true; } } cout<<modify_dijkstra(U, V); } } 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; }

Compilation message (stderr)

commuter_pass.cpp: In function 'std::vector<long long int> dijkstra(int)':
commuter_pass.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<item>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0; i<g[u].size(); ++i){
      |                  ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'll modify_dijkstra(int, int)':
commuter_pass.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<item>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0; i<g[u].size(); ++i){
      |                  ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:127:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |     freopen(task".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:128:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |     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...