Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: bradyawn
- PROG: contest
- LANG: C++11
- */
- #include <iostream>
- #include <algorithm>
- #include <iomanip>
- #include <fstream>
- #include <vector>
- #include <deque>
- #include <string>
- #include <cmath>
- #include <map>
- #include <unordered_map>
- #include <utility>
- #include <set>
- #include <unordered_set>
- #include <ctime>
- #include <queue>
- #include <stack>
- #include <bitset>
- #include <random>
- #include <cstring>
- #include <complex>
- #include <cassert>
- #define fi first
- #define se second
- #define pb push_back
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int,int> i2;
- typedef pair<ll,ll> ll2;
- int n, m, k;
- vector<pair<int, ll>> adj[50001];
- ll y[50001]; //yumminess in pasture i
- ll dist[2][50001]; //[eaten][node]
- //ll D[50001]; //[node]
- bool ans[50001];
- struct S
- {
- int cur;
- bool eat;
- ll d;
- friend bool operator<(const S &lhs, const S &rhs)
- {
- return lhs.d > rhs.d; //reverse order
- }
- };
- int main()
- {
- ifstream inf("dining.in");
- ofstream outf("dining.out");
- outf << setprecision(10);
- ios::sync_with_stdio(0); inf.tie(0);
- // memset(D, -1, sizeof D);
- inf >> n >> m >> k;
- for (int i = 1; i <= n; i++) dist[0][i] = dist[1][i] = 1e18;
- while (m--)//NEVER USE M AGAIN
- {
- int a, b, t; inf >> a >> b >> t;
- adj[a].pb({b,t});
- adj[b].pb({a,t});
- }
- while (k--)//NEVER USE K AGAIN
- {
- ll a, w;
- inf >> a >> w;
- y[a] = max(y[a], w);
- }
- //DONT COMPARE -1 with a numerical value LOL!
- priority_queue<S> pq;
- pq.push({n, 0, 0});
- while (!pq.empty())
- {
- auto node = pq.top(); pq.pop();
- int cur = node.cur;
- ll d = node.d;
- if (d >= dist[node.eat][cur]) continue;
- dist[node.eat][cur] = d;
- for (auto e : adj[cur])
- pq.push({e.fi, node.eat, d+e.se});
- if (!node.eat && y[cur] > 0) pq.push({cur, 1, d-y[cur]});
- }
- for (int i = 1; i < n; i++)
- outf << (dist[0][i] >= dist[1][i]) << '\n';
- return 0;
- }
- /*
- Read the problem carefully.
- Don't forget to sort(), mod, ll!!!!
- MULTISET NOT SET
- Initial value = +/- infinity instead of zero!!!
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement