QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584120#5073. Elden RingerduolongWA 127ms34344kbC++141.8kb2024-09-23 08:58:352024-09-23 08:58:37

Judging History

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

  • [2024-09-23 08:58:37]
  • 评测
  • 测评结果:WA
  • 用时:127ms
  • 内存:34344kb
  • [2024-09-23 08:58:35]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> PII;
const int N=1e6+10,Inf=1e9;
int w[N],c[N];
int T;
int n,m,A,B;
vector<int> e[N];
int d[N];
bool st[N];

void solve1()
{
	queue<int> q;
	for(int i=1;i<=n;i++) d[i]=-1;
	d[1]=0;
	q.push(1);
	while(q.size())
	{
		int u=q.front();q.pop();
		for(auto v:e[u])
		{
			if(d[v]!=-1) continue;
			if(w[1]+d[u]*(A-B)<=w[v]) d[v]=Inf;	
			else d[v]=d[u]+1,q.push(v);		
		}	
	}	
}

void solve2()
{
	priority_queue<int,vector<int>,greater<int>> heap;
	for(int i=2;i<=n;i++) 
	{
		heap.push(w[i]);
		c[i]=floor((double)(w[i]-w[1])/(A-B))+1;
		c[i]=max(0ll,c[i]);
		if(w[1]+c[i]*(A-B)<=w[i]) assert(0);
	}
	int maxc=0;
	while(heap.size())
	{
		if(heap.top()>=w[1]+maxc*(A-B)) break;
		maxc++,heap.pop();
	}
//	
//	cout<<maxc<<"\n"<<c[n]<<"\n";
//	return;
	
	for(int i=1;i<=n;i++) d[i]=Inf;
	d[1]=0;
	priority_queue<PII,vector<PII>,greater<PII>> Q;
	Q.push({d[1],1});
	while(Q.size())
	{
		auto it=Q.top();Q.pop();
		int u=it.second;
		if(st[u]) continue;
		st[u]=true;
		if(u==n) break;
		for(auto v:e[u])
		{
			if(c[v]>=maxc) continue;
			int w=max(d[u],c[v])+1;
			if(d[v]>w) 
			{
//				printf("edge: %d %d %d\n",u,v,w);
				d[v]=w;
				Q.push({d[v],v}); 
			}
		}
	}
}

void solve(int t)
{
	cin>>n>>m>>A>>B;
	for(int i=1;i<=n;i++) e[i].clear(),st[i]=0;
	for(int i=1,a,b;i<=m;i++)
	{
		cin>>a>>b;
		e[a].push_back(b),e[b].push_back(a); 
	}
	
	for(int i=1;i<=n;i++) cin>>w[i];
//	if(t!=5) return;
	
	for(int i=2;i<=n;i++) w[i]+=B;
	if(A<=B) solve1();
	else solve2();
	if(d[n]>=Inf) cout<<"-1\n";
	else cout<<d[n]<<"\n";
}

signed main()
{
//	freopen("ex_monster3.in","r",stdin);
	
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		solve(t);
	} 
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 34344kb

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: 127ms
memory: 30172kb

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