UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213357#2058. 小游戏huangyuhe0331ms6192kbC++111.4kb2024-11-11 19:53:412024-11-11 23:02:58

answer

#include <bits/stdc++.h>
#define C__ const
#define int long long
using namespace std;
C__ int N_ = 3e4 + 10, inf = 0x3f3f3f3f3f3f3f3fLL;
int n, m, k, a[N_];
vector<pair<int, int> > g[N_];
bool inq[N_];
set<pair<int, int> > res[N_];
int SPFA() {
	int ans = inf;
	queue<int> que;
	inq[1] = true, res[1].insert({k, 0}), que.push(1);
	while (!que.empty()) {
		int u = que.front(); que.pop(); inq[u] = false;
		for (pair<int, int> P : res[u]) {
			int hel = P.first, dis = P.second;
			if (u == n && hel > 0) ans = min(ans, dis);
			hel += a[u], hel = min(hel, k);
			for (pair<int, int> P : g[u]) {
				int v = P.first, w = P.second;
				if (hel - w > 0) {
					res[v].insert({hel - w, dis + 1});
					if (!inq[v]) inq[v] = true, que.push(v);
				}
			}
		}
		res[u].clear();
	}
	return ans;
}
signed main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		g[u].push_back({v, w});
	}
	cout << SPFA() << "\n";
	return 0;
}


/*
int bfs() {
int ans = inf;
queue<tuple<int, int, int> > que;
inq[1] = true, que.push({1, k, 0});
while (!que.empty()) {
auto [u, hel, dis] = que.front(); que.pop();
if (u == n && hel > 0) ans = min(ans, dis);
hel += a[u], hel = min(hel, k);
for (auto [v, w] : g[u]) {
if (hel - w > 0) que.push({v, hel - w, dis + 1});
}
}
return ans;
}
*/

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3356kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '1', found: '4557430888798830399'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 3356kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '-1', found: '4557430888798830399'

Test #3:

score: 0
Time Limit Exceeded

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:


result:


Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3356kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '10', found: '4557430888798830399'

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 3372kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '11', found: '4557430888798830399'

Test #6:

score: 0
Wrong Answer
time: 4ms
memory: 3384kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '11', found: '4557430888798830399'

Test #7:

score: 0
Wrong Answer
time: 8ms
memory: 3500kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '32', found: '4557430888798830399'

Test #8:

score: 0
Wrong Answer
time: 77ms
memory: 4760kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '39', found: '4557430888798830399'

Test #9:

score: 0
Wrong Answer
time: 134ms
memory: 6192kb

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:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '1726', found: '4557430888798830399'

Test #10:

score: 0
Wrong Answer
time: 106ms
memory: 6076kb

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 ...

output:

4557430888798830399

result:

wrong answer 1st lines differ - expected: '1594', found: '4557430888798830399'