이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 205;
const int MX_M = 5e4+5;
const int INF = 1e9;
struct Edge { int v, c, d, i; };
int N, M;
vector<Edge> al[MX_N];
int dist[2][MX_N];
void dijkstra(int s, vector<Edge>* al, int* dist, int blocked) {
fill(dist+1,dist+1+N,INF);
dist[s] = 0;
bool done[N+1];
fill(done+1,done+1+N,0);
while (true) {
int u = -1;
FOR(v,1,N) if (!done[v] && (u == -1 || dist[v] < dist[u])) u = v;
if (u == -1) break;
done[u] = 1;
for (auto e : al[u]) if (e.i != blocked) {
if (dist[u] + e.c < dist[e.v]) {
dist[e.v] = dist[u] + e.c;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
FOR(i,1,M){
int U, V, C, D; cin >> U >> V >> C >> D;
al[U].push_back({V,C,D,i});
}
dijkstra(1,al,dist[0],-1);
dijkstra(N,al,dist[1],-1);
int ans = min(INF, dist[0][N] + dist[1][1]);
FOR(u,1,N){
for (auto& e : al[u]) {
al[e.v].push_back({u,e.c,e.d,M+1});
dijkstra(1,al,dist[0],e.i);
dijkstra(N,al,dist[1],e.i);
al[e.v].pop_back();
ans = min(ans, dist[0][N] + dist[1][1] + e.d);
}
}
cout << (ans == INF ? -1 : ans) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |