Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <unordered_set>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6. #include <queue>
  7. #include <climits>
  8. using namespace std;
  9. typedef pair<int, int> ii;
  10.  
  11. unordered_set<int> H[50000];
  12. vector<ii> G[50000];
  13.  
  14. int main() {
  15. ifstream fin("dining.in");
  16. ofstream fout("dining.out");
  17.  
  18. int N, M, K;
  19. fin >> N >> M >> K;
  20. for (int i = 0; i < M; i++) {
  21. int a, b, t;
  22. fin >> a >> b >> t;
  23. G[a].push_back({ b, t });
  24. G[b].push_back({ a, t });
  25. }
  26. for (int i = 0; i < K; i++) {
  27. int p, y;
  28. fin >> p >> y;
  29. H[p].insert(y);
  30. }
  31.  
  32. vector<int> dist0(N + 1, INT_MAX / 2), dist1(N + 1, INT_MAX / 2);
  33. dist0[N] = 0;
  34. priority_queue<ii, vector<ii>, greater<ii>> pq0, pq1;
  35. pq0.push({ 0, N });
  36. while (!pq0.empty()) {
  37. int d = pq0.top().first, u = pq0.top().second;
  38. pq0.pop();
  39. if (d > dist0[u]) continue;
  40. for (auto &h : H[u]) {
  41. if (d - h < dist1[u]) {
  42. dist1[u] = d - h;
  43. pq1.push({ d - h, u });
  44. }
  45. }
  46. for (auto &v : G[u]) {
  47. if (dist0[u] + v.second < dist0[v.first]) {
  48. dist0[v.first] = dist0[u] + v.second;
  49. pq0.push({ dist0[v.first], v.first });
  50. }
  51. }
  52. }
  53. while (!pq1.empty()) {
  54. int d = pq1.top().first, u = pq1.top().second;
  55. pq1.pop();
  56. if (d > dist1[u]) continue;
  57. for (auto &v : G[u]) {
  58. if (dist1[u] + v.second < dist1[v.first]) {
  59. dist1[v.first] = dist1[u] + v.second;
  60. pq1.push({ dist1[v.first], v.first });
  61. }
  62. }
  63. }
  64.  
  65. for (int i = 1; i < N; i++) {
  66. cout << (dist0[i] < dist1[i] ? "0" : "1") << endl;
  67. fout << (dist0[i] < dist1[i] ? "0" : "1") << endl;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement