BCZSX @ 2019-10-09 21:53:41
WA了第八个点……
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define MAXN 10100
#define MAXM 50100
#define INF 2e9
struct Edge
{
int v, w, nxt;
} edge[MAXM << 1];
queue<int> que;
int n, m, b, u, v, w, cnt, ans;
int head[MAXN], f[MAXN], dis[MAXN], k[MAXN];
bool vis[MAXN];
void add_edge(int u, int v, int w)
{
edge[++cnt] = Edge{ v, w, head[u] };
head[u] = cnt;
}
bool check(int x)
{
//printf("%d %d %d\n", x, f[1], f[n]);
if (x < k[1] || x < k[n])
return 0;
memset(dis, INF, sizeof(dis));
for (int i = 1; i <= n; ++i)
vis[i] = (x < k[i]);
dis[1] = 0;
que.push(1);
while (!que.empty())
{
int x = que.front();
que.pop();
if (vis[x])
continue;
vis[x] = 1;
for (int i = head[x]; i; i = edge[i].nxt)
{
int v = edge[i].v;
int w = edge[i].w;
if (dis[v] > dis[x] + w)
{
dis[v] = dis[x] + w;
if (!vis[v])
que.push(v);
}
}
}
if (dis[n] <= b)
return 1;
return 0;
}
int main()
{
scanf("%d%d%d", &n, &m, &b);
for (int i = 1; i <= n; ++i)
scanf("%d", &k[i]), f[i] = k[i];
for (int i = 1; i <= m; ++i)
{
scanf("%d%d%d", &u, &v, &w);
if (u == v)
continue;
add_edge(u, v, w);
add_edge(v, u, w);
}
sort(f + 1, f + 1 + n);
if (!check(f[n]))
printf("AFK"), exit(0);
int l = 1, r = n;
ans = f[n];
while (l <= r)
{
int mid = (l + r) >> 1;
if (check(f[mid]))
ans = f[mid], r = mid - 1;
else
l = mid + 1;
}
printf("%d", ans);
return 0;
}
by StarLbright40 @ 2019-10-09 22:00:16
提一个不知有没有用的东西
memset是按字节赋值的,你把每个字节都赋为2e9不知会出什么事
一般用memset赋极大值的方法是
memset(dis, 0x3f, sizeof(dis));
把每个字节都赋为0x3f,相当于把数组中的每个数都赋为0x3f3f3f3f
by Kendrick_Z @ 2019-10-09 22:00:54
这题好像要long long...?
by StarLbright40 @ 2019-10-09 22:05:23
还有,
对于100%的数据,满足n≤1e4,m≤5e4,b≤1e9,ci≤1e9,fi≤1e9,
1e4*1e9=1e13会爆int
所以要开long long
by StarLbright40 @ 2019-10-09 22:05:35
@BCZSX
by BCZSX @ 2019-10-09 22:05:49
@星光0000 好的,谢谢
by BCZSX @ 2019-10-09 22:10:12
@星光0000 开了long long还是WA