QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#396584 | #5073. Elden Ring | 321625 | WA | 144ms | 10916kb | C++14 | 2.1kb | 2024-04-22 21:46:02 | 2024-04-22 21:46:04 |
Judging History
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==525)
{
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;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 10856kb
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: 144ms
memory: 10916kb
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:
10 -1 78243 73166 1 2 2 3 1 4 1 5 4 6 2 7 5 8 6 9 7 9 7 10 186663 119822 39982 137640 80774 38548 23495 164552 8666 75130
result:
wrong answer 1st numbers differ - expected: '-1', found: '10'