QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396583#5073. Elden Ring321625WA 157ms10420kbC++142.1kb2024-04-22 21:45:322024-04-22 21:45:33

Judging History

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

  • [2024-04-22 21:45:33]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:10420kb
  • [2024-04-22 21:45:32]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
const int N=2e5+7;
typedef long long ll;
std::vector<int> to[N];
struct pii{int v,d;};
bool operator<(pii x,pii y){return x.d>y.d;}
std::priority_queue<pii> pq;
int h[N],c[N],dis[N];bool vis[N];
inline int cldiv(int a,int b){return (a+b-1)/b;}
inline int fldiv(int a,int b){if(!b)return a>=0?1e9:-1;return a>=0?a/b:(a-b+1)/b;}
int main()
{
	int T,n,m,A,B,eu,ev;scanf("%d",&T);
	for(int cas=1;cas<=T;++cas)
	{
		scanf("%d%d%d%d",&n,&m,&A,&B);
		for(int i=1;i<=n;++i)to[i].clear();
		while(m--)scanf("%d%d",&eu,&ev),to[eu].push_back(ev),to[ev].push_back(eu);
		for(int i=1;i<=n;++i)scanf("%d",h+i),i>1&&(h[i]+=B,0);
		if(A<=B)
		{
			const int D=B-A;
			for(int i=2;i<=n;++i)c[i]=fldiv(h[1]-h[i]-1,D);//,printf("c[%d]=%d\n",i,c[i]);
			memset(dis+1,0x3f,n*sizeof*dis);memset(vis+1,0,n*sizeof*vis);
			pq.push({1,dis[1]=0});
			while(!pq.empty())
			{
				int i=pq.top().v;pq.pop();if(vis[i])continue;
				for(int v:to[i])if(dis[i]+1<std::min(dis[v],c[v]+2))pq.push({v,dis[v]=dis[i]+1});
			}
		}
		else
		{
			const int D=A-B;int H=c[1]=-1;memset(vis+1,0,n*sizeof*vis);
			for(int i=2;i<=n;++i)c[i]=(h[i]<=h[1]?0:cldiv(h[i]-h[1]+1,D));//,printf("c[%d]=%d\n",i,c[i]);
			pq.push({1,0});
			while(!pq.empty())
			{
				int i=pq.top().v;pq.pop();/*printf("i=%d H=%d\n",i,H);*/if(H<c[i])break;++H;
				for(int v:to[i])if(!vis[v])pq.push({v,c[v]}),vis[v]=1;
			}
			while(!pq.empty())pq.pop();
			//printf("H=%d\n",H);
			memset(dis+1,0x3f,n*sizeof*dis);memset(vis+1,0,n*sizeof*vis);
			int t;pq.push({1,dis[1]=0});
			while(!pq.empty())
			{
				int i=pq.top().v;pq.pop();/*printf("dis[%d]=%d\n",i,dis[i]);*/if(vis[i])continue;
				for(int v:to[i])if(c[v]<H&&(t=std::max(dis[i],c[v])+1)<dis[v])pq.push({v,dis[v]=t});
			}
		}
//		if(T!=1e5)
		printf("%d\n",dis[n]<=n?dis[n]:-1);
//		else if(cas==484)
//		{
//			printf("%d %d %d %d\n",n,m,A,B);
//		for(int i=1;i<=n;++i)for(int v:to[i])if(v<i)printf("%d %d\n",v,i);
//		for(int i=1;i<=n;++i)printf("%d ",h[i]-(i==1?0:B));
//			
//		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 157ms
memory: 10420kb

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