QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295901#5073. Elden RingzzuqyWA 166ms24380kbC++142.4kb2024-01-01 14:44:392024-01-01 14:44:39

Judging History

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

  • [2024-01-01 14:44:39]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:24380kb
  • [2024-01-01 14:44:39]
  • 提交

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];
	bool vst[MAXN];
	void bfs() {
		a[1] -= A;
		int cnt = 0;
		for (int i = 0; i <= n + 1; i++)
			v[i].clear(), d[i] = 1000000000, vst[i] = 0;
		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 = 0;
		while (h <= t) {
			if(h==t){
				for (; len <= cnt; len++) {
					if (v[len].size() == 0)
						continue;
					while(v[len].size()){
						int x = v[len].back();
						q[++t]=x;
						d[x]=len;
						v[len].pop_back();
					}
					
					break;
				}
			} 
			int x=0;
			if(++h<=t)x = q[h],len=d[x];
			else return;
			//cout<<x<<" "<<h<<" "<<t<<endl;
			cnt++;
			go(x) {
				int tn = ver[i];
				if (vst[tn] == 1)
					continue;
				vst[tn] = 1;
				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;
			}
			v[len].clear();
		}
	}
}

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;
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 153ms
memory: 22848kb

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:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 166ms
memory: 22404kb

input:

100000
10 10 7791 61545
9 3
3 10
7 4
2 1
3 4
2 6
8 2
2 3
5 2
3 2
142757 98694 34871 181188 28671 62924 172723 13856 11576 26661
10 10 194165 132103
2 5
8 7
3 1
7 3
1 2
6 1
4 9
1 3
4 3
10 4
176824 47360 148701 4531 66460 199228 135267 149448 65763 125940
9 10 152778 128023
3 1
3 2
1 2
1 6
5 7
5 2
4 7...

output:

-1
-1
7
-1
-1
-1
-1
-1
-1
4
-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
4
-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
4
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
1
3
-1
-1
1
1
-1
-1
-1
5
1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer 2270th numbers differ - expected: '3', found: '4'