제출 #233725

#제출 시각아이디문제언어결과실행 시간메모리
233725dualityOlympic Bus (JOI20_ho_t4)C++11
100 / 100
394 ms4472 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; struct edge { int v,c,d,i; }; vector<edge> adjList[2][200]; int dist1[200],dist2[200],dist3[200],dist4[200],dist5[200],dist6[200]; priority_queue<pii> H; int inTree[50000]; int findPath(int u,int *dist,int N,int r,edge rev) { int i; for (i = 0; i < N; i++) dist[i] = -1; dist[u] = 0,H.push(mp(0,u)); while (!H.empty()) { int u = H.top().second; int d = -H.top().first; H.pop(); if (d > dist[u]) continue; for (i = 0; i < adjList[r][u].size(); i++) { int v = adjList[r][u][i].v; if (adjList[r][u][i].i == rev.i) continue; if ((dist[v] == -1) || (dist[u]+adjList[r][u][i].c < dist[v])) { dist[v] = dist[u]+adjList[r][u][i].c; if (rev.i == -1) inTree[adjList[r][u][i].i] = 1; H.push(mp(-dist[v],v)); } } if (u == rev.v) { int v = rev.d; if ((dist[v] == -1) || (dist[u]+rev.c < dist[v])) { dist[v] = dist[u]+rev.c; H.push(mp(-dist[v],v)); } } } return 0; } int main() { int i; int N,M; int U,V,C,D; scanf("%d %d",&N,&M); for (i = 0; i < M; i++) { scanf("%d %d %d %d",&U,&V,&C,&D); U--,V--; adjList[0][U].pb((edge){V,C,D,i}); adjList[1][V].pb((edge){U,C,D,i}); } int j,ans = 2e9; findPath(0,dist1,N,0,(edge){-1,-1,-1,-1}),findPath(N-1,dist2,N,1,(edge){-1,-1,-1,-1}); findPath(0,dist3,N,1,(edge){-1,-1,-1,-1}),findPath(N-1,dist4,N,0,(edge){-1,-1,-1,-1}); if ((dist1[N-1] != -1) && (dist4[0] != -1)) ans = dist1[N-1]+dist4[0]; for (i = 0; i < N; i++) { for (j = 0; j < adjList[0][i].size(); j++) { int v = adjList[0][i][j].v; if (!inTree[adjList[0][i][j].i]) { if ((dist1[v] != -1) && (dist2[i] != -1) && (dist4[0] != -1)) ans = min(ans,dist1[v]+dist2[i]+dist4[0]+adjList[0][i][j].c+adjList[0][i][j].d); if ((dist1[N-1] != -1) && (dist4[v] != -1) && (dist3[i] != -1)) ans = min(ans,dist1[N-1]+dist4[v]+dist3[i]+adjList[0][i][j].c+adjList[0][i][j].d); if ((dist1[v] != -1) && (dist2[i] != -1) && (dist4[v] != -1) && (dist3[i] != -1)) ans = min(ans,dist1[v]+dist2[i]+dist4[v]+dist3[i]+2*adjList[0][i][j].c+adjList[0][i][j].d); } } } for (i = 0; i < N; i++) { for (j = 0; j < adjList[0][i].size(); j++) { int v = adjList[0][i][j].v; if (inTree[adjList[0][i][j].i]) { int x = 2e9; if ((dist1[v] != -1) && (dist2[i] != -1) && (dist4[0] != -1)) x = min(x,dist1[v]+dist2[i]+dist4[0]+adjList[0][i][j].c+adjList[0][i][j].d); if ((dist1[N-1] != -1) && (dist4[v] != -1) && (dist3[i] != -1)) x = min(x,dist1[N-1]+dist4[v]+dist3[i]+adjList[0][i][j].c+adjList[0][i][j].d); if ((dist1[v] != -1) && (dist2[i] != -1) && (dist4[v] != -1) && (dist3[i] != -1)) x = min(x,dist1[v]+dist2[i]+dist4[v]+dist3[i]+2*adjList[0][i][j].c+adjList[0][i][j].d); if (x >= ans) continue; edge e = adjList[0][i][j]; e.d = i; findPath(0,dist5,N,0,e),findPath(N-1,dist6,N,0,e); if ((dist5[N-1] != -1) && (dist6[0] != -1)) ans = min(ans,dist5[N-1]+dist6[0]+adjList[0][i][j].d); } } } if (ans == 2e9) printf("-1\n"); else printf("%d\n",ans); return 0; }

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

ho_t4.cpp: In function 'int findPath(int, int*, int, int, edge)':
ho_t4.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[r][u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:61:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[0][i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:74:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[0][i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
ho_t4.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d",&U,&V,&C,&D);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...