Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <map>
- #include <vector>
- #include <algorithm>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define int long long
- #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
- #define all(v) v.begin(),v.end()
- #define ep(a,b) emplace_back(make_pair(a,b))
- #define pii pair<int,int>
- #define heap pii,vector<pii>,greater<pii>
- using namespace std;
- using namespace __gnu_pbds;
- typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>__indexed_set;
- const int N = 1e6+9;
- const int MOD = 1e9+7;
- const int add = 50000;
- int dist[N];
- vector<pii>v[N];
- map<int,int>cost;
- int n,m,p;
- void bfs(int node)
- {
- priority_queue<heap>q;
- for (int i = 0; i < N; ++i)
- {
- dist[i] = MOD;
- }
- dist[node] = 0;
- q.push({0LL,node});
- while(!q.empty())
- {
- int w = q.top().first;
- int nod = q.top().second;
- //cerr<<"current node: "<<nod<<"\tweight: "<<w<<'\n';
- q.pop();
- for (auto i : v[nod])
- {
- if (dist[i.first] > dist[nod]+i.second+cost[i.first])
- {
- dist[i.first] = dist[nod]+i.second+cost[i.first];
- q.push({dist[i.first],i.first});
- }
- }
- }
- }
- void solve()
- {
- cin>>n>>m>>p;
- for (int i = 0,x,y,z; i < m; ++i)
- {
- cin>>x>>y>>z;
- x += add;
- y += add;
- v[x].ep(y,z);
- v[y].ep(x,z);
- }
- for (int i = 0,x,y; i < p; ++i)
- {
- cin>>x>>y;
- x += add;
- cost[x] += y;
- }
- bfs(52077LL);
- if (dist[52024LL] > n)
- {
- cout<<"IOI\n";
- }
- else
- {
- cout<<"NO KAMP\n";
- }
- //cout<<"distances: "<<dist[52077]<<"\n"<<dist[52025]<<'\n'<<dist[52024]<<'\n';
- }
- signed main()
- {
- $AzH_TxdmN$
- int t = 1;
- //cin>>t;
- while(t--)
- {
- solve();
- }
- }
- /*
- 10 2 1
- 2077 2025 1
- 2025 2024 1
- 2024 9
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement