QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800040#6306. Chase Game19077frb#WA 2ms7988kbC++232.1kb2024-12-05 20:37:092024-12-05 20:37:09

Judging History

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

  • [2024-12-05 20:37:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7988kb
  • [2024-12-05 20:37:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Endl '\n'
#define pb push_back
#define pll pair<ll,ll>
const int N=2e5+3;
const ll INF=1e18;
int n,m,k,d;
ll dk[N],dn[N],d1[N];
ll atk[N];
vector<int> e[N];
bool vis[N];
void solve()
{
    cin>>n>>m>>k>>d;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        e[u].pb(v);
        e[v].pb(u);
    }
    for(int i=1;i<=n;i++)
    {
        dk[i]=INF;
        d1[i]=INF;
        dn[i]=INF;
    }
    queue<ll> q;
    dk[k]=0;
    q.push(k);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v:e[u])
        {
            if(dk[v]!=INF)continue;
            dk[v]=dk[u]+1;
            q.push(v);
        }
    }
    dn[n]=1;
    q.push(n);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v:e[u])
        {
            if(dn[v]!=INF)continue;
            dn[v]=dn[u]+1;
            q.push(v);
        }
    }
    priority_queue<pll> pq;
    d1[1]=0;
    pq.push({-d1[1],1});
    while(!pq.empty())
    {
        int u=pq.top().second;
        pq.pop();
        if(vis[u])continue;
        vis[u]=1;
        for(auto v:e[u])
        {
            int w;
            if(d-dk[v]>0)
                w=d-dk[v];
            else
                w=d;
            if(d1[u]+w<d1[v])
            {
                d1[v]=d1[u]+w;
                pq.push({-d1[v],v});
            }
        }
    }
    if(dk[n]<d)
    {
        cout<<d1[n]<<Endl;
        return;
    }
    ll now=d;
    for(int i=1;i<=n;i++)
    {
        atk[i]=atk[i-1]+now;
        now--;
        if(now==0)now=d;
    }
    if(dk[1]>=d)
    {
        cout<<atk[dn[1]-1]<<Endl;
        return;
    }
    ll ans=INF;
    for(int i=1;i<=n;i++)
    {
        if(dk[i]==d-1)
        {
            ans=min(ans,d1[i]+atk[dn[i]-1]);
        }
    }
    cout<<ans<<Endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _=1;
    // cin>>_;
    while(_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 1ms
memory: 7988kb

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:

9

result:

wrong answer 1st numbers differ - expected: '7', found: '9'