QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572203 | #5073. Elden Ring | ciuim | WA | 55ms | 32520kb | C++14 | 3.2kb | 2024-09-18 12:55:53 | 2024-09-18 12:55:53 |
Judging History
answer
bool M1;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<" MB\n"
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#define i128 __int128
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define fo(a,b,c) for(ll a=b;a<=c;++a)
#define re(a,b,c) for(ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<ll> ::iterator
using namespace std;
const ll mod=1e9+7;
inline ll gi()
{
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
ll _=1;
const ll inf=2e17+5,iinf=2e9;
const ll N=1000005;
ll n,m,A,B;
vector<ll> g[N];
ll delt,dis[N],w[N];
struct st
{
bool operator()(pii za,pii zb)
{
return za.fi>zb.fi;
}
};
priority_queue<pii,vector<pii>,st> q;
ll dijm()
{
while(!q.empty()) q.pop();
fo(i,0,n) dis[i]=inf;
dis[1]=0;
q.push({0,1});
while(!q.empty())
{
pii p=q.top();
q.pop();
ll u=p.se;
for(ll v:g[u])
{
if(dis[v]>dis[u]+1&&w[v]<w[1]-delt*dis[u])
{
dis[v]=dis[u]+1;
q.push({dis[v],v});
}
}
}
if(dis[n]>n) return -1;
return dis[n];
}
ll dijx()
{
while(!q.empty()) q.pop();
fo(i,0,n) dis[i]=0;
ll cnt=-1;
q.push({0,1});
while(!q.empty())
{
pii p=q.top();
q.pop();
ll u=p.se;
if(dis[u]) continue;
if(u==1||w[u]<w[1]+cnt*delt)
{
cnt++;
}
else
{
return 0;
}
dis[u]=1;
for(ll v:g[u])
{
if(dis[v]==0) q.push({w[v],v});
}
}
if(dis[n]) return 1;
return 0;
}
ll lim[N];
ll dijn()
{
while(!q.empty()) q.pop();
fo(i,0,n) dis[i]=inf;
dis[1]=0;
fo(i,2,n)
{
ll z=w[i]-w[1]+1;
if(z<=0)
{
lim[i]=-inf;
continue;
}
ll num=z/delt;
if(z%delt) num++;
lim[i]=num;
}
q.push({0,1});
while(!q.empty())
{
pii p=q.top();
q.pop();
ll u=p.se;
for(ll v:g[u])
{
if(dis[v]>max(lim[v]+1,dis[u]+1))
{
dis[v]=max(lim[v]+1,dis[u]+1);
q.push({dis[v],v});
}
}
}
return dis[n];
}
void sol()
{
n=gi(),m=gi(),A=gi(),B=gi();
fo(i,1,n) g[i].clear();
ll ok1=0;
fo(i,1,m)
{
ll x=gi(),y=gi();
g[x].pb(y);
g[y].pb(x);
if(x==1&&y==n) ok1=1;
if(x==n&&y==1) ok1=1;
}
fo(i,1,n) w[i]=gi();
fo(i,2,n) w[i]+=B;
if(w[1]>w[n]) ok1|=2;
if(A<=B)
{
delt=B-A;
ll ans=dijm();
if(ans==-1&&ok1==3)
{
cout<<"TEST 1";
return;
}
cout<<ans;
return;
}
delt=A-B;
if(dijx())
{
cout<<dijn();
return;
}
cout<<-1;
}
bool M2;
int main()
{
// freopen("monster.in","r",stdin);
// freopen("monster.out","w",stdout);
int Time=clock();
look_memory;
_=gi();
while(_--)
{
sol();
printf("\n");
}
look_time;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 31808kb
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: 55ms
memory: 32520kb
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 -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 -1 3 -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 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 4th numbers differ - expected: '1', found: '-1'