QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646402#5073. Elden RingKevin5307WA 135ms5632kbC++232.6kb2024-10-16 22:46:462024-10-16 22:46:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 22:46:47]
  • 评测
  • 测评结果:WA
  • 用时:135ms
  • 内存:5632kb
  • [2024-10-16 22:46:46]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int t,n,m;
ll A,B;
ll l[200200];
vector<int> G[200200];
int dist[200200];
int vis1[200200],vis2[200200];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n>>m>>A>>B;
		for(int i=1;i<=n;i++)
			G[i].clear();
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			G[u].pb(v);
			G[v].pb(u);
		}
		for(int i=1;i<=n;i++)
		{
			cin>>l[i];
			if(i>1)
				l[i]+=B;
		}
		if(A<=B)
		{
			for(int i=1;i<=n;i++)
				dist[i]=-1;
			queue<int> q;
			dist[1]=0;
			q.push(1);
			while(!q.empty())
			{
				int x=q.front();
				q.pop();
				for(auto y:G[x])
					if(dist[y]==-1&&l[y]+B*dist[x]<l[1]+A*dist[x])
					{
						dist[y]=dist[x]+1;
						q.push(y);
					}
			}
			cout<<dist[n]<<'\n';
		}
		else
		{
			for(int i=1;i<=n;i++)
				vis1[i]=vis2[i]=0;
			int cnt=0;
			queue<int> q;
			priority_queue<pii,vector<pii>,greater<pii>> pq;
			q.push(1);
			vis1[1]=vis2[1]=1;
			for(auto j:G[1])
			{
				vis1[j]=1;
				pq.emplace(l[j],j);
			}
			while(!q.empty())
			{
				int x=q.front();
				q.pop();
				cnt++;
				while(!pq.empty()&&pq.top().first<l[1]+(A-B)*(cnt-1))
				{
					int u=pq.top().second;
					vis1[u]=1;
					q.push(u);
					pq.pop();
					for(auto v:G[u])
						if(!vis2[v])
						{
							vis2[v]=1;
							pq.emplace(l[v],v);
						}
				}
			}
			if(!vis1[n])
				cout<<"-1\n";
			else
			{
				for(int i=1;i<=n;i++)
					dist[i]=inf;
				priority_queue<pii,vector<pii>,greater<pii>> pq;
				dist[1]=0;
				pq.emplace(0,1);
				while(!pq.empty())
				{
					int x=pq.top().second;
					int d=pq.top().first;
					pq.pop();
					if(dist[x]!=d) continue;
					for(auto y:G[x])
						if(vis1[y])
						{
							int nd=max(d+1ll,(l[y]>=l[1])?(max(0ll,l[y]-l[1])/(A-B)+2):0);
							if(nd<dist[y])
							{
								dist[y]=nd;
								pq.emplace(nd,y);
							}
						}
				}
				cout<<dist[n]<<'\n';
			}
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

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: 135ms
memory: 5632kb

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
18
-1
-1
-1
2
-1
-1
-1
9
-1
-1
22
-1
28
-1
-1
47
-1
-1
-1
-1
-1
-1
26
18
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
26
-1
27
3
-1
-1
3
-1
2
-1
-1
255
1
-1
-1
-1
-1
-1
80
59
-1
30
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
46
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
7
-1...

result:

wrong answer 18th numbers differ - expected: '-1', found: '18'