QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377072#5073. Elden RingInfinityNS#WA 180ms13112kbC++142.0kb2024-04-04 21:22:272024-04-04 21:22:28

Judging History

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

  • [2024-04-04 21:22:28]
  • 评测
  • 测评结果:WA
  • 用时:180ms
  • 内存:13112kb
  • [2024-04-04 21:22:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long

const int N=200050;
vector<int> E[N];
ll ans;
ll l[N];

ll dist[N];
void SolveDec(int n,int m,ll A,ll B){
	for(int i=1;i<=n;i++)dist[i]=-1;
	queue<int> q;
	q.push(1);
	dist[1]=0;
	while(q.size()){
		int u=q.front();
		q.pop();
		for(int v:E[u]){
			if(dist[v]==-1){
				if(l[v]+B*dist[u]<l[1]+A*dist[u]){
					dist[v]=dist[u]+1;
					q.push(v);
				}
			}
		}
	}
	ans=dist[n];
}
bool was[N];
int TakeMax(int n,int m,ll A,ll B){
	priority_queue<pair<ll,int>> pq;
	for(int i=1;i<=n;i++)was[i]=false;
	was[1]=true;
	for(int i:E[1]){
		was[i]=true;
		pq.push({-l[i],i});
	}
	int ans=0;
	while(pq.size()){
		int u=pq.top().second;
		pq.pop();
		if(l[u]+B*ans<l[1]+A*ans)ans++;
		else break;
		for(int v:E[u]){
			if(!was[v]){
				was[v]=true;
				pq.push({-l[v],v});
			}
		}
	}
	return ans;
}
const int inf=1e9+7;
ll mn[N];
void SolveInc(int n,int m,ll A,ll B){
	int mxd=TakeMax(n,m,A,B);
	for(int i=1;i<=n;i++)dist[i]=inf;
	ll diff=A-B;
	for(int i=2;i<=n;i++){
		ll p=l[i]-l[1];
		if(p<0)mn[i]=0;
		else mn[i]=(p+diff-1)/diff;
	}
	priority_queue<pair<ll,int>> pq;
	dist[1]=0;
	pq.push({0,1});
	while(pq.size()){
		int u=pq.top().second;
		int d=-pq.top().first;
		pq.pop();
		if(dist[u]!=d)continue;
		for(int v:E[u]){
			if(dist[v]>max(mn[v]+1,dist[u]+1)){
				dist[v]=max(mn[v]+1,dist[u]+1);
				pq.push({-dist[v],v});
			}
		}
	}
	if(dist[n]>mxd)ans=-1;
	else ans=dist[n];
}
int main(){
	int t;
	scanf("%i",&t);
	while(t--){
		int n,m,A,B;
		scanf("%i %i %i %i",&n,&m,&A,&B);
		for(int i=1;i<=m;i++){
			int u,v;
			scanf("%i %i",&u,&v);
			E[u].pb(v);
			E[v].pb(u);
		}
		for(int i=1;i<=n;i++)scanf("%lld",&l[i]);
		for(int i=2;i<=n;i++)l[i]+=B;
		if(A<=B){
			SolveDec(n,m,A,B);
		}else{
			SolveInc(n,m,A,B);
		}
		printf("%lld\n",ans);

		for(int i=1;i<=n;i++){
			E[i].clear();
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13112kb

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: 180ms
memory: 12124kb

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 559th numbers differ - expected: '-1', found: '6'