QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295650#5073. Elden Ringzzuqy#WA 0ms15968kbC++142.2kb2023-12-31 18:06:552023-12-31 18:06:56

Judging History

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

  • [2023-12-31 18:06:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15968kb
  • [2023-12-31 18:06:55]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#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];
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;
			}
		}
	}
}

namespace sub2 {
	vector<int>v[MAXN];
	int hi[MAXN];
	void bfs() {
		a[1] -= A;
		int cnt = 0;
		for (int i = 0; i <= n + 1; i++)
			v[i].clear(), d[i] = 1000000000;
		for (int i = 2; i <= n; i++) {
			hi[i] = max(0, (a[i] - a[1]) / (A - B) + 1);
			if (hi[i] > MAXN)
				hi[i] = MAXN - 1;
			//cout << hi[i] << " ";
		}
		h = 0;
		q[t = 1] = 1;
		d[1] = 0;
		int len = 1;
		while (h <= t) {
			int x = -1;
			if (h + 1 <= t) {
				h++;
				x = q[h];
				len = d[x];
			} else {
				//cout << ">>:" << cnt << endl;
				for (; len <= cnt; len++) {
					if (v[len].size() == 0)
						continue;
					x = v[len].back();
					d[x] = len;
					v[len].pop_back();
				}
			}
			if (x == -1)
				return;
			cnt++;
			go(x) {
				int tn = ver[i];
				if (d[tn] == 1000000000) {
					if (d[x] + 1 >= hi[tn]) {
						d[tn] = d[x] + 1;
						q[++t] = tn;
					} else
						v[hi[tn]].push_back(tn);
				}
			}
			for (auto tn : v[len]) {
				d[tn] = len;
				q[++t] = tn;
			}
		}
	}
}

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;
		}
		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 {
			sub2::bfs();
			if (d[n] != 1000000000)
				printf("%d\n", d[n]);
			else
				printf("-1\n");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 15968kb

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:


result:

wrong answer Answer contains longer sequence [length = 2], but output contains 0 elements