QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295894#5073. Elden RingzzuqyWA 158ms4508kbC++141.9kb2024-01-01 14:12:312024-01-01 14:12:32

Judging History

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

  • [2024-01-01 14:12:32]
  • 评测
  • 测评结果:WA
  • 用时:158ms
  • 内存:4508kb
  • [2024-01-01 14:12:31]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include<utility>
#define ll long long
#define rep(a,b,c) for(int c=a;c<=b;++c)
#define sc(A) scanf("%d",&A)
#define go(x) for(int i=lin[x];i;i=nex[i])
using namespace std;
const int MAXN = 400010;
int n, A, B, m;
int T, len, t, h;
int d[MAXN], a[MAXN], q[MAXN],b[MAXN],vis[MAXN];
int lin[MAXN], ver[MAXN], nex[MAXN];

inline void add(int x, int y) {
	ver[++len] = y;
	nex[len] = lin[x];
	lin[x] = len;
}

void bfs() {
	h = 0;
	q[t = 1] = 1;
	d[1] = 1;
	while (++h <= t) {
		int x = q[h];
		go(x) {
			int tn = ver[i];
			if (!d[tn] && a[1] + (ll)(d[x] - 1) * A - (ll)B * d[x] > a[tn]) {
				d[tn] = d[x] + 1;
				q[++t] = tn;
			}
		}
	}
}
priority_queue< pair<int,int> >s;
void bfs1()
{
	A-=B;
	rep(2,n,i)
	{
		a[i]+=B;
		if(a[i]<a[1])b[i]=0;
		else b[i]=(a[i]-a[1])/A+1;
	}
	go(1)
	{
		int tn=ver[i];
		if(vis[tn])continue;
		s.push(make_pair(-b[tn],tn));
		vis[tn]=1;
	}
	h=1;t=0;
	vis[1]=1;
	int sz=0;
	rep(1,n,i)
	{
		if(sz<i-1)break;
		while(s.size())
		{
			int x=s.top().second;
			int y=-s.top().first;
			if(y>=i)break;
			s.pop();
			++sz;
			d[x]=i+1;
			go(x)
			{
				int tn=ver[i];
				if(vis[tn])continue;
				//s.push(make_pair(-b[tn],tn));
				q[++t]=tn;
				vis[tn]=1;
			}
		}
		rep(h,t,j)s.push(make_pair(-b[q[j]],q[j]));
		h=t+1;
	}
}

int main() {
	//freopen("1.in", "r", stdin);
	sc(T);
	while (T--) {
		sc(n);
		sc(m);
		sc(A);
		sc(B);
		len = 0;
		rep(1, n, i) {
			lin[i] = 0;
			d[i] = 0;
			vis[i]=0;
		}
		rep(1, m, i) {
			int x, y;
			sc(x);
			sc(y);
			add(x, y);
			add(y, x);
		}
		rep(1, n, i)sc(a[i]);
		if (A <= B) 
		{
			bfs();
			printf("%d\n", d[n] - 1);
		}
		else
		{
			bfs1();
			printf("%d\n", d[n] - 1);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 158ms
memory: 4508kb

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 222nd numbers differ - expected: '3', found: '5'