UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213485#2058. 小游戏erican1001252ms13268kbC++112.0kb2024-11-12 15:28:312024-11-12 15:28:32

answer

// Problem: B. 小游戏
// Contest: undefined - NOIP2024训练赛 02
// URL: http://noi.ac/contest/1154/problem/2058
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=2e5+5;
const ull P=137;
const int INF=1e18+7;
/*

策略


*/	




struct Node{
	int v,w;
};vector<Node> e[N];

int d[N],g[N];
int n,m,V;
int w[N];

void add(int c,int b,int a){
	e[a].pb({b,c});
	e[b].pb({a,c});
}

struct Suff{
	int v,d,g;
	bool operator<(const Suff b)const{
		return d>b.d;
	}
};

priority_queue<Suff> q;

void spfa(){
	memset(d,0x3f3f,sizeof d);
	d[1]=0;
	g[1]=V;
	
	q.push({1,0,V});
	while(q.size()){
		int x=q.top().v;
		int dd=q.top().d;
		int gg=q.top().g;
		q.pop();
		if(x==n){
			cout<<dd;;
			exit(0) ;
		}
		for(auto v:e[x]){
			if(g[v.v]>=min(V,gg-v.w+w[v.v])||gg-v.w<=0)continue;
			g[v.v]=min(V,gg-v.w+w[v.v]);
			d[v.v]=dd+1;
			q.push({v.v,d[v.v],g[v.v]});
		}
	}
	
}

signed main(){
	 n=rd,m=rd,V=rd;
	 
	 for(int i=1;i<=n;i++){
	 	w[i]=rd;
	 }
	for(int i=1;i<=m;i++){
		add(rd,rd,rd);
	}
	
	
	spfa();
	
	cout<<-1;
}



详细

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 7476kb

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: 10
Accepted
time: 0ms
memory: 7484kb

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:

-1

result:

ok single line: '-1'

Test #3:

score: 10
Accepted
time: 0ms
memory: 7476kb

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: 7476kb

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: 1ms
memory: 7512kb

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: 0ms
memory: 7564kb

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: 10
Accepted
time: 5ms
memory: 7756kb

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:

32

result:

ok single line: '32'

Test #8:

score: 10
Accepted
time: 38ms
memory: 10340kb

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:

39

result:

ok single line: '39'

Test #9:

score: 10
Accepted
time: 572ms
memory: 13268kb

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:

1726

result:

ok single line: '1726'

Test #10:

score: 10
Accepted
time: 636ms
memory: 13264kb

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:

1594

result:

ok single line: '1594'