Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <unordered_set>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <queue>
- #include <climits>
- using namespace std;
- typedef pair<int, int> ii;
- unordered_set<int> H[50000];
- vector<ii> G[50000];
- int main() {
- ifstream fin("dining.in");
- ofstream fout("dining.out");
- int N, M, K;
- fin >> N >> M >> K;
- for (int i = 0; i < M; i++) {
- int a, b, t;
- fin >> a >> b >> t;
- G[a].push_back({ b, t });
- G[b].push_back({ a, t });
- }
- for (int i = 0; i < K; i++) {
- int p, y;
- fin >> p >> y;
- H[p].insert(y);
- }
- vector<int> dist0(N + 1, INT_MAX / 2), dist1(N + 1, INT_MAX / 2);
- dist0[N] = 0;
- priority_queue<ii, vector<ii>, greater<ii>> pq0, pq1;
- pq0.push({ 0, N });
- while (!pq0.empty()) {
- int d = pq0.top().first, u = pq0.top().second;
- pq0.pop();
- if (d > dist0[u]) continue;
- for (auto &h : H[u]) {
- if (d - h < dist1[u]) {
- dist1[u] = d - h;
- pq1.push({ d - h, u });
- }
- }
- for (auto &v : G[u]) {
- if (dist0[u] + v.second < dist0[v.first]) {
- dist0[v.first] = dist0[u] + v.second;
- pq0.push({ dist0[v.first], v.first });
- }
- }
- }
- while (!pq1.empty()) {
- int d = pq1.top().first, u = pq1.top().second;
- pq1.pop();
- if (d > dist1[u]) continue;
- for (auto &v : G[u]) {
- if (dist1[u] + v.second < dist1[v.first]) {
- dist1[v.first] = dist1[u] + v.second;
- pq1.push({ dist1[v.first], v.first });
- }
- }
- }
- for (int i = 1; i < N; i++) {
- cout << (dist0[i] < dist1[i] ? "0" : "1") << endl;
- fout << (dist0[i] < dist1[i] ? "0" : "1") << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement