제출 #1130307

#제출 시각아이디문제언어결과실행 시간메모리
1130307am_aadvikOlympic Bus (JOI20_ho_t4)C++17
0 / 100
1102 ms190016 KiB
#include <iostream> #include<set> #include<map> #include<vector> #define inf 1e17 #define int long long using namespace std; vector<vector<int>> g[205][2]; vector<vector<int>> e; vector<vector<int>> dist[2]; //path, node, rev. edg int32_t main() { int n, m; cin >> n >> m; dist[0].assign(n + 1, vector<int>(m + 1, inf)); dist[1].assign(n + 1, vector<int>(m + 1, inf)); e.push_back({}); //1 based idxing for (int i = 1; i <= m; ++i) { int u, v, c, d; cin >> u >> v >> c >> d; g[u][0].push_back({ v, c ,d, i }); g[v][1].push_back({ u, c, d, i }); e.push_back({ u, v, c ,d }); } set<vector<int>> s; //{dist+cost, node, path, rev. edg.} s.insert({ 0, 1, 0, 0 }), dist[0][1][0] = 0; while (s.size()) { vector<int> f = *s.begin(); s.erase(s.begin()); if (f[2] && (f[1] == 1)) { //complete! cout << f[0]; return 0; } if (f[1] == n) f[2] = 1; //1 way complete! for (auto x : g[f[1]][0]) { //out edgs. if (f[3] != x[3]) { //this edg. wasnt rev. int val = dist[f[2]][x[0]][f[3]]; if (val > (f[0] + x[1])) { if (val != inf) s.erase({ val, x[0], f[2], f[3] }); dist[f[2]][x[0]][f[3]] = (f[0] + x[1]); s.insert({ (f[0] + x[1]), x[0], f[2], f[3] }); } } } if (f[3] == 0) { for (auto x : g[f[1]][1]) { //in edgs. f[3] = x[3]; int val = dist[f[2]][x[0]][f[3]]; if (val > (f[0] + x[1] + x[2])) { if (val != inf) s.erase({ val, x[0], f[2], f[3] }); dist[f[2]][x[0]][f[3]] = (f[0] + x[1] + x[2]); s.insert({ (f[0] + x[1] + x[2]), x[0], f[2], f[3] }); } f[3] = 0; } } } cout << -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...