Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- #include <vector>
- #include <queue>
- #include <utility>
- using namespace std;
- long long int n ,m ,k;
- using pr = pair<long long int, long long int>;
- long long int INF = 2e9;
- vector<pr> g[100010];
- int main(){
- cin >> n >> m >> k;
- long long int u1 ,v1 ,d1;
- for(int i=0;i<m;++i){
- cin >> u1 >> v1 >> d1;
- g[u1].push_back(make_pair(v1,d1));
- g[v1].push_back(make_pair(u1,d1));
- }
- vector <long long int> dist(n+1,INF);
- vector <bool> visit(n+1,false);
- priority_queue<pr, vector<pr>, greater<pr>> q;
- dist[1]=0;
- q.push({dist[1],1});
- long long int max1=1;
- while(!q.empty()){
- long long int u = q.top().second , d = q.top().first;
- q.pop();
- if(visit[u]){
- continue;
- }
- visit[u] = true;
- if(dist[u]<=k && max1<u){
- max1 =u;
- }
- for(auto c : g[u]){
- long long int x = c.first;
- long long int y = c.second;
- if(!visit[x]&&dist[u]+y < dist[x]){
- dist[x]=dist[u]+y;
- q.push({dist[x],x});
- }
- }
- }
- cout << max1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement