제출 #869378

#제출 시각아이디문제언어결과실행 시간메모리
869378vjudge1Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
78 ms17068 KiB
#include <iostream> #include <limits> #include <vector> #include <set> #include <cstdint> using namespace std; using Pair = pair<int64_t, int64_t>; struct Edge { int64_t w, v, u; }; constexpr int64_t maxn = 100000, inf = numeric_limits<int64_t>::max(); int64_t n, m, x1, y1, x2, y2; Edge edge[maxn + 1]; vector<int64_t> adj[maxn + 1]; bool isVisited[maxn + 1]; bool DFS(int64_t v = x1) { isVisited[v] = true; bool result = v == y1; for (int64_t e : adj[v]) { int64_t u = edge[e].v + edge[e].u - v; if (isVisited[u]) continue; if (DFS(u)) { edge[e].w = 0; result = true; } } return result; } int64_t Dijkstra() { for (int64_t i = 1; i <= n; i++) isVisited[i] = false; set<Pair> q; vector d = vector<int64_t>(n + 1, inf); q.insert(make_pair(0, x2)); d[x2] = 0; while (q.size() > 0) { int64_t v = q.begin()->second; q.erase(q.begin()); isVisited[v] = true; for (int64_t e : adj[v]) { int64_t u = edge[e].v + edge[e].u - v; if (isVisited[u]) continue; if (d[u] > d[v] + edge[e].w) { d[u] = d[v] + edge[e].w; q.insert(make_pair(d[u], u)); } } } return d[y2]; } int main() { cin >> n >> m >> x1 >> y1 >> x2 >> y2; for (int64_t i = 1; i <= m; i++) { cin >> edge[i].v >> edge[i].u >> edge[i].w; adj[edge[i].v].push_back(i); adj[edge[i].u].push_back(i); } DFS(); cout << Dijkstra() << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...