QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298019 | #6306. Chase Game | PlentyOfPenalty# | WA | 6ms | 16104kb | C++20 | 1.6kb | 2024-01-05 15:56:30 | 2024-01-05 15:56:30 |
Judging History
answer
#include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long ll;
bool umin(ll& a,ll t){if(t<a)return a=t,1;return 0;}
const int MAXN = 400011;
struct edge{int v,w,nxt;}e[MAXN<<1|1];
int cnt=1,last[MAXN];
void adde(int u,int v,int w)
{
e[++cnt].v=v,e[cnt].w=w;
e[cnt].nxt=last[u],last[u]=cnt;
}
std::vector<int>a[MAXN];
int dk[MAXN],dn[MAXN];
void bfs(int* dep,int s,int n)
{
static int Q[MAXN];
int h=0,t=0;
Q[t++]=s,dep[s]=1;
while(h<t)
{
int u=Q[h++];
for(auto v:a[u])
if(!dep[v])dep[v]=dep[u]+1,Q[t++]=v;
}
for(int u=1;u<=n;++u)--dep[u];
}
struct node
{
int u;ll dis;
node(){}
node(int _u,ll _dis){u=_u,dis=_dis;}
bool operator< (const node& you)const{return dis>you.dis;}
};
std::priority_queue<node>Q;
ll dis[MAXN],f[MAXN];
void Dij(int s)
{
memset(dis,0x3f,sizeof dis);
dis[s]=0,Q.push(node(s,0));
while(Q.size())
{
node tp=Q.top();Q.pop();
int u=tp.u;
if(dis[u]!=tp.dis)continue;
for(int i=last[u];i;i=e[i].nxt)
{
int v=e[i].v,w=e[i].w;
if(umin(dis[v],dis[u]+w))Q.push(node(v,dis[v]));
}
}
}
int main(){
#ifdef memset0
freopen("I.in","r",stdin);
#endif
std::cin.tie(0)->sync_with_stdio(0);
int n,m,k,d;
cin>>n>>m>>k>>d;
for(int i=1;i<=m;++i)
{
int u,v;
cin>>u>>v;
a[u].emplace_back(v),a[v].emplace_back(u);
}
bfs(dn,n,n),bfs(dk,k,n);
for(int u=1;u<=n;++u)
for(auto v:a[u])
if(dk[v]<d)adde(u,v,d-dk[v]);
Dij(1);
f[0]=d;
for(int i=1;i<=n;++i)
f[i]=f[i-1]+(d-i%d);
ll ans=dis[n];
for(int u=1;u<=n;++u)
for(auto v:a[u])
if(dk[u]<d&&dk[v]==d)
umin(ans,dis[u]+f[dn[v]]);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 15972kb
input:
5 5 3 1 1 2 2 4 4 5 1 3 3 5
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 3ms
memory: 15968kb
input:
13 17 12 3 1 2 2 3 3 4 4 13 5 13 7 8 7 9 7 10 7 11 7 6 12 7 1 8 8 9 9 10 10 11 11 6 6 13
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 16104kb
input:
10 9 4 1 4 3 1 2 7 6 6 5 8 9 9 10 5 4 8 7 3 2
output:
4557430888798830399
result:
wrong answer 1st numbers differ - expected: '9', found: '4557430888798830399'