QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800019#6306. Chase Game19077frb#WA 2ms9832kbC++232.0kb2024-12-05 20:26:152024-12-05 20:26:16

Judging History

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

  • [2024-12-05 20:26:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9832kb
  • [2024-12-05 20:26:15]
  • 提交

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;
    }
    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: 9832kb

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: 1ms
memory: 7984kb

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: 0
Accepted
time: 1ms
memory: 7992kb

input:

10 9 4 1
4 3
1 2
7 6
6 5
8 9
9 10
5 4
8 7
3 2

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 9708kb

input:

10 20 9 1
9 5
2 9
4 5
10 5
7 3
1 8
7 1
7 5
3 4
3 1
7 8
3 8
9 3
10 6
9 1
1 6
8 5
6 2
1 10
2 1

output:

3

result:

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