Submission #219891

#TimeUsernameProblemLanguageResultExecution timeMemory
219891sensielCommuter Pass (JOI18_commuter_pass)C++11
0 / 100
359 ms19820 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_NODE = 100005; const int INFINI = 100000000; typedef struct node { int iNode; int prix; }node; typedef struct event { int tps; int iNode; int parent; bool operator< (const event & other)const { return tps > other.tps; } }event; int nNode; int nArc; int S,T; int U,V; vector<node> adj[MAX_NODE]; int minDisU[MAX_NODE]; int minDisV[MAX_NODE]; int tpsmin[MAX_NODE]; int dp[MAX_NODE][2][2]; void init() { scanf("%d %d", &nNode, &nArc); scanf("%d %d", &S, &T); scanf("%d %d", &U, &V); for(int iArc = 0; iArc < nArc; iArc++) { int a,b,c; scanf("%d %d %d", &a, &b, &c); adj[a].push_back({b,c}); adj[b].push_back({a,c}); } for(int iNode = 0; iNode <= nNode; iNode++) { minDisU[iNode] = INFINI; minDisV[iNode] = INFINI; tpsmin[iNode] = INFINI; dp[iNode][false][false] = 0; dp[iNode][true][false] = INFINI; dp[iNode][true][true] = INFINI; dp[iNode][false][true] = INFINI; } dp[0][false][false] = INFINI; } int main() { init(); priority_queue<event> dU; dU.push({0,U,-1}); while(!dU.empty()) { event actual = dU.top(); dU.pop(); if(actual.tps <= minDisU[actual.iNode]) { minDisU[actual.iNode] = actual.tps; int nVoisin = adj[actual.iNode].size(); for(int iVoisin = 0; iVoisin < nVoisin; iVoisin++) { node voisin = adj[actual.iNode][iVoisin]; if(minDisU[voisin.iNode] >= actual.tps + voisin.prix) { minDisU[voisin.iNode] = actual.tps + voisin.prix; dU.push({minDisU[voisin.iNode], voisin.iNode, actual.iNode}); } } } } priority_queue<event> dV; dV.push({0,V,-1}); while(!dV.empty()) { event actual = dV.top(); dV.pop(); if(actual.tps <= minDisV[actual.iNode]) { minDisV[actual.iNode] = actual.tps; int nVoisin = adj[actual.iNode].size(); for(int iVoisin = 0; iVoisin < nVoisin; iVoisin++) { node voisin = adj[actual.iNode][iVoisin]; if(minDisV[voisin.iNode] >= actual.tps + voisin.prix) { minDisV[voisin.iNode] = actual.tps + voisin.prix; dV.push({minDisV[voisin.iNode], voisin.iNode, actual.iNode}); } } } } priority_queue<event> pq; pq.push({0,S,0}); while(!pq.empty()) { event actual = pq.top(); pq.pop(); if(actual.tps <= tpsmin[actual.iNode]) { tpsmin[actual.iNode] = actual.tps; dp[actual.iNode][false][true] = min(dp[actual.iNode][false][true], min(dp[actual.parent][false][true], minDisU[actual.iNode])); dp[actual.iNode][true][false] = min(dp[actual.iNode][true][false], min(dp[actual.parent][true][false], minDisV[actual.iNode])); dp[actual.iNode][true][true] = min(dp[actual.iNode][true][true], min( dp[actual.parent][true][true], min(minDisV[actual.iNode] + minDisU[actual.iNode], min(dp[actual.iNode][true][false] + minDisU[actual.iNode], dp[actual.iNode][false][true] + minDisV[actual.iNode])))); int nVoisin = adj[actual.iNode].size(); for(int iVoisin = 0; iVoisin < nVoisin; iVoisin++) { node voisin = adj[actual.iNode][iVoisin]; if(tpsmin[voisin.iNode] >= actual.tps + voisin.prix) { tpsmin[voisin.iNode] = actual.tps + voisin.prix; pq.push({tpsmin[voisin.iNode], voisin.iNode, actual.iNode}); } } } } printf("%d %d", min(minDisU[V], dp[T][true][true])); }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:147:52: warning: format '%d' expects a matching 'int' argument [-Wformat=]
  printf("%d %d", min(minDisU[V], dp[T][true][true]));
                                                    ^
commuter_pass.cpp: In function 'void init()':
commuter_pass.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &nNode, &nArc);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &S, &T);
  ~~~~~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &U, &V);
  ~~~~~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...