제출 #1272567

#제출 시각아이디문제언어결과실행 시간메모리
1272567witek_cppRobot (JOI21_ho_t4)C++20
0 / 100
83 ms10348 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <queue> using namespace std; typedef long long ll; #define st first #define nd second #define f(a, c, b) for (int a = c; b > a; a++) #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) int(a.size()) vector<vector<int>> g; //bedzie zawierac ind krawedzi vector<unordered_map<int, int>> ile; //ile wchodzi danego rodzaju do wierzcholka vector<pair<pair<int, int>, pair<int, ll>>> e; //krawedzie pair<int, pair<int, ll>> kr(int v, int ind) { if (e[ind].st.st == v) return {e[ind].st.nd, {e[ind].nd.st, e[ind].nd.nd}}; return {e[ind].st.st, e[ind].nd}; } ll wnk = 213769420696969; int main() { //ios_base::sync_with_stdio(0); //cin.tie(0); int n, m; cin >> n >> m; g.resize(n + 1); e.resize(m); ile.resize(n + 1); f(i, 0, m) { int a, b, c; ll p; cin >> a >> b >> c >> p; ile[a][c]++; ile[b][c]++; g[a].pb(i); g[b].pb(i); e[i] = {{a, b}, {c, p}}; } const ll DUZO = 1000000; priority_queue<pair<ll, ll>> kolejka; //koszt - zahaszowany wierzcholek kolejka.push({0, 1}); unordered_map<ll, ll> ans; //odpowiedzi while (!kolejka.empty()) { ll koszt = -kolejka.top().st; if (ans.find(kolejka.top().nd) != ans.end()) break; ans[kolejka.top().nd] = koszt; int v = kolejka.top().nd%(DUZO); int ind = kolejka.top().nd/DUZO; //cout << "int v to " << v << " ind to " << ind << " "; kolejka.pop(); if (v == n) wnk = min(wnk, koszt); int kolor = -1; if (ind != 0) { kolor = kr(v, ind).nd.st; ile[v][kolor]--; } //cout << "a"; for (int ele: g[v]) { //cout << ele << " "; pair<int, pair<int, ll>> u = kr(v, ele); if (ile[v][u.nd.st] == 1) { if (ans.find(u.st) == ans.end()) { kolejka.push({-koszt, u.st}); } } else { ll pot = u.st + ll(ele) * DUZO; if (ans.find(pot) == ans.end()) { kolejka.push({-(koszt + u.nd.nd), pot}); } } } if (kolor != -1) ile[v][kolor]++; //cout << "\n"; } if (wnk == 213769420696969) { cout << -1; } else { cout << wnk; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...