ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213348 | #2058. 小游戏 | WZRYWZWY | 50 | 166ms | 9852kb | C++11 | 1.3kb | 2024-11-11 19:08:52 | 2024-11-11 23:01:36 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 3e4 + 5;
int n, m; // 点数、血量上限
int hp[N];
struct node {
int v, d; // 目标点、据起点距离
int bl; // 血量
};
map <PII, bool> vis; // 目标点,剩余血量
map <PII, int> dis;
struct cmp {
bool operator()(node a, node b) {
return a.d > b.d;
}
};
priority_queue <node, vector <node>, cmp> q;
vector <PII> e[N];
void BFS(int s) {
dis[{s, m}] = 0;
//vis[{s, m}] = 1;
q.push({s, 0, m});
while (q.size()) {
int u = q.top().v, bl = q.top().bl;
//cout << u << " " << bl << "\n";
if (u == n) {
cout << q.top().d;
exit(0);
}
q.pop();
if (vis[{u, bl}]) continue;
vis[{u, bl}] = 1;
//cout << u << " " << bl << " " << dd << "\n";
for (auto to : e[u]) {
int p = min(bl + hp[u], m) - to.second;
if (p <= 0) continue;
int v = to.first;
if (dis[{v, p}] > dis[{u, bl}] + 1 || !dis[{v, p}]) {
dis[{v, p}] = dis[{u, bl}] + 1;
q.push({v, dis[{v, p}], p});
}
}
}
}
signed main() {
cin.tie(0); ios::sync_with_stdio(0);
int E; cin >> n >> E >> m;
for (int i = 1; i <= n; i++) cin >> hp[i];
while (E--) {
int x, y, z; cin >> x >> y >> z;
e[x].push_back({y, z});
e[y].push_back({x, z});
}
BFS(1);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1976kb
input:
5 10 10 3 3 0 1 1 4 4 1 4 3 1 3 2 6 3 4 10 5 1 5 1 3 9 2 5 19 2 5 1 5 2 10 2 1 4
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1924kb
input:
5 10 10 1 0 1 3 0 5 2 1 5 2 8 4 3 18 1 3 10 5 3 5 2 3 8 5 3 15 3 1 11 4 5 9 2 4 1
output:
result:
wrong answer 1st lines differ - expected: '-1', found: ''
Test #3:
score: 10
Accepted
time: 1ms
memory: 1972kb
input:
5 10 10 0 3 1 1 1 1 3 12 5 4 8 1 1 6 5 2 1 2 5 3 1 4 2 1 4 4 4 5 5 4 2 9 3 4 2
output:
2
result:
ok single line: '2'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1996kb
input:
20 50 20 4 0 3 4 3 0 5 2 5 0 5 2 5 2 0 6 2 3 4 2 16 5 18 9 1 24 14 16 27 5 16 32 14 7 31 13 20 23 6 ...
output:
10
result:
ok single line: '10'
Test #5:
score: 10
Accepted
time: 3ms
memory: 2100kb
input:
100 500 20 2 5 5 3 0 1 1 3 4 2 5 5 5 4 5 3 1 0 2 5 5 5 2 2 1 4 0 1 6 0 1 5 2 4 5 4 4 6 3 0 0 1 5 1 3...
output:
11
result:
ok single line: '11'
Test #6:
score: 10
Accepted
time: 162ms
memory: 9852kb
input:
500 1000 500 143 113 118 133 51 100 155 76 81 43 8 91 85 65 61 69 1 30 135 125 0 43 126 20 40 52 165...
output:
11
result:
ok single line: '11'
Test #7:
score: 0
Time Limit Exceeded
input:
1000 5000 1000 94 154 195 48 124 134 103 168 192 122 101 8 5 197 62 123 36 129 90 48 24 43 104 7 108...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
10000 50000 10000 30 96 44 6 84 58 47 34 35 80 49 45 47 76 93 16 2 83 23 79 81 12 66 81 96 3 37 4 69...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
30000 100000 20000 21 95 28 93 22 5 16 70 27 36 38 21 7 11 8 46 88 19 98 80 70 53 73 83 79 93 55 75 ...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
30000 100000 20000 94 72 1 42 14 15 63 14 26 25 44 9 1 71 75 85 98 80 87 49 10 47 73 16 98 13 62 72 ...