QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789357 | #5073. Elden Ring | Moloch | WA | 0ms | 15432kb | C++14 | 2.6kb | 2024-11-27 20:02:48 | 2024-11-27 20:02:53 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <bitset>
//#define int long long
#define LL long long
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
char gc()
{
if(p1 == p2){p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin);}
return *(p1) ++;
}
LL read()
{
LL x = 0, s = 1;
// scanf("%lld", &x); return x;
char ch = gc();
if(ch < '0' || ch > '9'){s = ch == '-' ? -1 : s; ch = gc();}
while('0' <= ch && ch <= '9'){x = (x << 1ll) + (x << 3ll) + (ch ^ 48); ch = gc();}
return x * s;
}
void write(int x)
{
if(x > 9){write(x / 10);}
putchar(x % 10 + '0');
}
const int N = 2e5 + 10;
const int INF = 1e9 + 10;
int n, m, ai, bi;
int li[N];
vector<int> e[N];
int dis[N], st[N];
queue<int> q;
void bfs_ls()
{
int dv = ai - bi;
dis[1] = 0; st[1] = 1; q.push(1);
while(q.size())
{
int x = q.front(); q.pop();
for(int y : e[x])
{
if(st[y] || li[y] > li[1] + dv * dis[x]){continue;}
st[y] = 1; dis[y] = dis[x] + 1; //dis[y] = min(dis[x] + 1, dis[y]);
q.push(y);
}
}
}
vector<int> po[N];
int cedi(int x, int y)
{
if(x < 0){return -1;}
return x % y ? x / y + 1ll : x / y;
}//ceil
typedef pair<int, int> PII;
priority_queue<PII, vector<PII>, greater<PII> > he;
void bfs_gr()
{
int dv = ai - bi;
dis[1] = 0; st[1] = 1; po[0].push_back(1);
int prs = 0;
for(int tim = 0; tim <= n; tim ++)
{
for(int x : po[tim])
{
for(int y : e[x])
{
if(!st[y]){he.push({li[y], y}); st[y] = 1;}
}
}
if(tim){prs += po[tim].size();}
while(he.size())
{
int y = he.top().second, tmp = cedi(li[y] - li[1], dv);
if(tmp <= prs){dis[y] = max(tim, tmp) + 1; po[dis[y]].push_back(y); he.pop();}
else{break;}
}
}
}
void init()
{
while(he.size()){he.pop();}
while(q.size()){q.pop();}
for(int i = 0; i <= n; i ++)
{
dis[i] = INF; st[i] = li[i] = 0;
e[i].clear(); po[i].clear();
}
}
int qid = 0;
void solve()
{
n = read(); m = read(); ai = read(); bi = read();
init();
for(int i = 1; i <= m; i ++){int u = read(), v = read(); e[u].push_back(v); e[v].push_back(u);}
for(int i = 1; i <= n; i ++){li[i] = read();}
for(int i = 2; i <= n; i ++){li[i] += bi + 1;}//变成小于等于
if(ai <= bi){bfs_ls();}
else{bfs_gr();}
if(dis[n] <= n - 1){write(dis[n]);}
else{puts("-1");}
}
signed main()
{
int tii = read();
for(int z = 1; z <= tii; z ++){qid = z; solve();}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 15432kb
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:
24
result:
wrong answer 1st numbers differ - expected: '2', found: '24'