touristX @ 2018-10-01 10:47:38
求教WA on #8,输出了AFK,求dalao找错(码风不好见谅)
#include <bits/stdc++.h>
#define reg register
using namespace std;
typedef long long LL;
const int N = 20005;
const int M = 100005;
const LL inf = 1e16;
LL cost[N], kil[M], dis[N], le = inf, ri, mid;
int n, m, b, cnt, head[M], nxt[M], to[M];
bool vis[N], wr;
inline LL read() {
reg char c; LL x = 0;
for (c = getchar(); c < '0'|| c > '9'; c = getchar());
for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x;
}
struct cmp { bool operator () (int a,int b) { return dis[a] > dis[b]; } };
priority_queue < LL, vector < LL >, cmp > q;
inline void Add_Edge (int u, int v, LL w) { to[++cnt] = v, kil[cnt] = w, nxt[cnt] = head[u], head[u] = cnt; }
inline void done () { for (reg int i = 2; i <= n; ++i) dis[i] = inf, memset(vis, 0, sizeof vis); }
int main() {
n = read(), m = read(), b = read();
for (reg int i = 1; i <= n; ++i)
cost[i] = read(), ri = max (ri, cost[i]), le = min (le, cost[i]);
for (reg int i = 1, u, v, w; i <= m; ++i)
u = read(), v = read(), w = read(), Add_Edge(u, v, w), Add_Edge(v, u, w);
++ri;
while (le <= ri) {
mid = le + ri >> 1, done(), q.push(1);
while (!q.empty()) {
LL p = q.top();
q.pop(), vis[p] = 0;
for (reg int i = head[p]; i; i = nxt[i])
if (cost[to[i]] <= mid && dis[p] + kil[to[i]] < dis[to[i]]) {
dis[to[i]] = dis[p] + kil[to[i]];
if (!vis[to[i]]) q.push(to[i]), vis[to[i]] = 1;
}
}
if (dis[n] >= b) le = mid + 1;
else ri = mid - 1, wr = 1;
}
if(!wr) puts ("AFK");
else cout << le;
return 0;
}
by touristX @ 2018-10-01 11:00:33
@aoweiyin 血量不能为0注意了的,
但是“第一个点要判一下”这句话可不可以展开一下,我太弱了看不懂
by 桜Sakura @ 2018-10-01 11:01:13
您为什么一定要强调是刚学OI(真)呢?
by touristX @ 2018-10-01 11:01:56
我为什么一定要强调是刚学OI(真)呢?
by Fading @ 2018-10-01 11:02:58
刚学OI系列...
by Carbon @ 2018-10-01 11:03:16
天天刚学OI有意思吗
by xiangling @ 2018-10-01 11:17:15
码风有毒...
by aoweiyin @ 2018-10-01 15:15:35
@touristX 详见你大号私信
by aoweiyin @ 2018-10-01 15:16:09
@起名真的很难