1 solutions

  • 1
    @ 2025-10-4 10:36:06

    亲测能过

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    const int N = 1e5 + 5;
    int a[N], dis[N], f[N];
    
    struct node {
    	int v, w;
    };
    vector<node>e[N];
    int n, m, b;
    
    int ch(int x) {
    	memset(f, 0, sizeof(f));
    	priority_queue<pair<int, int>>q;
    	q.push({0, 1});
    	memset(dis, 0x3f, sizeof(dis));
    	dis[1] = 0;
    	while (!q.empty()) {
    		int now = q.top().second;
    		q.pop();
    		if (f[now])
    			continue;
    		f[now] = 1;
    		for (auto [v, w] : e[now]) {
    //			int v = e[now][i].v, w = e[now][i].w;
    			if (dis[v] > dis[now] + w and x >= a[v])
    				dis[v] = dis[now] + w, q.push({-dis[v], v});
    		}
    	}
    	return dis[n] <= b;
    }
    
    signed main() {
    	cin >> n >> m >> b;
    	for (int i = 1; i <= n; i++)
    		cin >> a[i];
    	for (int i = 1; i <= m; i++) {
    		int x, y, z;
    		cin >> x >> z >> y;
    		e[x].push_back({z, y});
    		e[z].push_back({x, y});
    	}
    	int l = a[1], r = 1e9, ans = -1;
    	while (l <= r) {
    		int mid = (l + r) >> 1;
    		if (ch(mid))
    			ans = mid, r = mid - 1;
    		else
    			l = mid + 1;
    	}
    	if (ans == -1)
    		cout << "AFK";
    	else
    		cout << ans;
    	return 0;
    }
    
    • @ 2025-10-4 10:36:22

      人民万岁!!

Information

ID
5575
Time
1000ms
Memory
512MiB
Difficulty
4
Tags
# Submissions
118
Accepted
26
Uploaded By