Submission #1235652

#TimeUsernameProblemLanguageResultExecution timeMemory
1235652iamhereforfunRobot (JOI21_ho_t4)C++20
0 / 100
156 ms14332 KiB
// IamHereForFun // #include <bits/stdc++.h> using namespace std; #define LSOne(X) ((X) & -(X)) const int N = 1e5 + 5; const int M = 11; const int L = 12; const int LG = 25; const int P = 37; const int INF = 1e9 + 5; const int MOD = 1e9 + 7; const int nx[] = {0, -1, 0, 1}, ny[] = {-1, 0, 1, 0}; // find shortest path, for every node, calculate minimum path // problemo: because everytime you change an edge, it affects the next node too =)) // lets say you change a edge, then you should change it so that it doesn't affect the next one =)) // but if you change a edge for another edge to be valid, then you shouldn't go to the node that it's connect too, other wise just use it // so we use dp[N] as normal, but in your pq, you save a number indicating that the edge that leads to it is changed or not int n, m; long long dp[N]; vector<array<int, 3>> adj[N]; bool vis[N]; void solve() { cin >> n >> m; for (int x = 1; x <= n; x++) { dp[x] = INF; } for (int x = 0; x < m; x++) { int a, b, c, p; cin >> a >> b >> c >> p; adj[a].push_back({b, c, p}); adj[b].push_back({a, c, p}); } priority_queue<array<long long, 3>> pq; dp[1] = 0; pq.push({0, 0, 1}); while (!pq.empty()) { array<long long, 3> arr = pq.top(); pq.pop(); int i = arr[2]; if(vis[i]) continue; vis[i] = true; map<int, long long> mp; for(array<int, 3> a : adj[i]) { if(a[0] == arr[2] && arr[1]) continue; mp[a[1]] += a[2]; } for(array<int, 3> a : adj[i]) { long long val = mp[a[1]] - a[2]; int j = a[0]; if(dp[j] > dp[i] + val) { dp[j] = dp[i] + val; pq.push({-dp[j], 0, j}); } if(dp[j] > dp[i] + a[2]) { dp[j] = dp[i] + a[2]; pq.push({-dp[j], 1, j}); } } } if(dp[n] == INF) { cout << -1 << "\n"; } else { cout << dp[n] << "\n"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for (int x = 1; x <= t; x++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...