Submission #135216

#TimeUsernameProblemLanguageResultExecution timeMemory
135216dualityCommuter Pass (JOI18_commuter_pass)C++11
100 / 100
495 ms20948 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- vpii adjList[100000]; LLI distS[100000],distT[100000],distU[100000],distV[100000]; priority_queue<pair<LLI,int> > H; int findDist(int s,LLI *dist,int N) { int i; for (i = 0; i < N; i++) dist[i] = -1; dist[s] = 0,H.push(mp(0,s)); while (!H.empty()) { int u = H.top().second; LLI d = -H.top().first; H.pop(); if (d > dist[u]) continue; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i].first; if ((dist[v] == -1) || (d+adjList[u][i].second < dist[v])) { dist[v] = d+adjList[u][i].second; H.push(mp(-dist[v],v)); } } } return 0; } LLI dist1[100000],dist2[100000]; int visited[100000]; LLI doDFS(int u,LLI *a,LLI *b,LLI *c) { if (visited[u]) return c[u]; int i; visited[u] = 1,c[u] = b[u]; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i].first; if (a[u] == a[v]+adjList[u][i].second) c[u] = min(c[u],doDFS(v,a,b,c)); } return c[u]; } int main() { int i; int N,M; int S,T,U,V; int A,B,C; scanf("%d %d %d %d %d %d",&N,&M,&S,&T,&U,&V); S--,T--,U--,V--; for (i = 0; i < M; i++) { scanf("%d %d %d",&A,&B,&C); A--,B--; adjList[A].pb(mp(B,C)); adjList[B].pb(mp(A,C)); } findDist(S,distS,N),findDist(T,distT,N); findDist(U,distU,N),findDist(V,distV,N); LLI ans = distU[V]; for (i = 0; i < N; i++) doDFS(i,distS,distU,dist1); fill(visited,visited+N,0); for (i = 0; i < N; i++) doDFS(i,distT,distV,dist2); for (i = 0; i < N; i++) { if (distS[i]+distT[i] == distS[T]) ans = min(ans,dist1[i]+dist2[i]); } fill(visited,visited+N,0); for (i = 0; i < N; i++) doDFS(i,distS,distV,dist1); fill(visited,visited+N,0); for (i = 0; i < N; i++) doDFS(i,distT,distU,dist2); for (i = 0; i < N; i++) { if (distS[i]+distT[i] == distS[T]) ans = min(ans,dist1[i]+dist2[i]); } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int findDist(int, LLI*, int)':
commuter_pass.cpp:71:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'LLI doDFS(int, LLI*, LLI*, LLI*)':
commuter_pass.cpp:87:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d %d %d",&N,&M,&S,&T,&U,&V);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:101:14: 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...