QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311409 | #5073. Elden Ring | Watware | WA | 1414ms | 10448kb | C++17 | 2.2kb | 2024-01-22 12:33:11 | 2024-01-22 12:33:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int M = 201000;
using Type = pair<int, int>;
using PQue = priority_queue<Type, vector<Type>, greater<Type>>;
int T, n, m, a, b, l[M], p[M], dis[M];
vector<int> e[M];
inline void solveA() {
if (a != b)
for (int i = 2; i <= n; i++) p[i] = (l[1] - l[i]) / (b - a);
else
for (int i = 2; i <= n; i++) p[i] = l[1] >= l[i] ? INT_MIN : INT_MAX;
PQue q;
memset(dis, 0x3f, sizeof(dis));
dis[1] = 0, q.push({dis[1], 1});
while (!q.empty()) {
auto [d, o] = q.top();
q.pop();
if (d != dis[o]) continue;
for (int i : e[o])
if (dis[i] > dis[o] + 1 && p[i] >= dis[o] + 1) dis[i] = dis[o] + 1, q.push({dis[i], i});
}
printf("%d\n", dis[n] > n ? -1 : dis[n]);
}
inline void solveB() {
for (int i = 2; i <= n; i++) p[i] = max(0, (int) ceil(1.0 * (l[1] - l[i]) / (b - a)));
int _Tmp = 0;
for (int i = 2; i <= n; i++) _Tmp = max(_Tmp, p[i]);
PQue q, s;
memset(dis, 0, sizeof(dis));
q.push({0, 1}), dis[1] = 1;
int cnt = 0;
while (!q.empty()) {
auto [_, o] = q.top();
q.pop();
if (p[o] > cnt) return printf("-1\n"), void();
if (o == n) goto print;
cnt++;
for (int i : e[o])
if (!dis[i]) q.push({p[i], i}), dis[i] = 1;
}
return printf("-1\n"), void();
print:
memset(dis, 0x3f, sizeof(dis));
dis[1] = 0, s.push({dis[1], 1});
while (!s.empty()) {
auto [d, o] = s.top();
s.pop();
if (dis[o] != d) continue;
for (int i : e[o]) {
int t = max(dis[o] + 1, p[i]);
// int t = dis[o] + 1;
if (dis[i] > t) dis[i] = t, s.push({dis[i], i});
}
}
printf("%d\n", dis[n]);
}
inline void solve() {
assert(scanf("%d%d%d%d", &n, &m, &a, &b));
for (int i = 1; i <= n; i++) e[i].clear();
for (int i = 1, u, v; i <= m; i++)
assert(scanf("%d%d", &u, &v)), e[u].push_back(v), e[v].push_back(u);
for (int i = 1; i <= n; i++) assert(scanf("%d", l + i));
l[1] -= a;
if (a <= b) solveA();
else solveB();
}
int main() {
assert(scanf("%d", &T));
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 10448kb
input:
2 5 4 5 8 1 2 1 3 1 4 4 5 15 1 1 1 1 5 4 10 5 1 2 1 3 1 4 4 5 10 4 4 4 19
output:
2 4
result:
ok 2 number(s): "2 4"
Test #2:
score: -100
Wrong Answer
time: 1414ms
memory: 10296kb
input:
100000 6 10 107812 105568 6 5 3 6 4 6 4 2 5 1 5 6 4 5 1 3 1 2 2 5 124065 140875 29890 80077 116532 35394 9 10 82107 88302 1 2 2 3 5 3 5 1 1 4 9 6 3 5 8 2 5 6 7 5 22670 3735 33660 92823 139960 89319 83335 158330 117349 6 10 181257 173221 5 3 3 4 3 1 5 1 2 1 3 6 3 1 6 2 3 6 4 3 76902 46253 123092 2661...
output:
-1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 2 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 ...
result:
wrong answer 15868th numbers differ - expected: '-1', found: '1'