QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627998#6306. Chase GameTokaiZaopen#WA 0ms3616kbC++232.6kb2024-10-10 18:03:072024-10-10 18:03:10

Judging History

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

  • [2024-10-10 18:03:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-10 18:03:07]
  • 提交

answer

#include <bits/stdc++.h>

#define int ll
using ll = long long;

// #define MING_LE

const int mod = 998244353;
const int inf = 1e18;

using namespace std;

struct info
{
    int to;
    int w;
};

struct node
{
    int dis;
    int u;

    bool operator>(const node &o) const
    {
        return dis > o.dis;
    }
};

int n, m;
int pos, d;

vector<vector<info>> a;
vector<vector<info>> b;
int dis[100010];
int w[100010];
int sum[100010];
bool vis[100010];

void dij(vector<vector<info>> &e, int st);
void solve();

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int __ = 1;
    // cin >> __;

    while (__--)
        solve();

    return 0;
}

void solve()
{
    cin >> n >> m >> pos >> d;
    a.resize(n + 5);
    b.resize(n + 5);
    vector<int> viss(n + 5, 0);
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        a[u].push_back({v, 1});
        a[v].push_back({u, 1});
    }

    dij(a, pos);
    for (int i = 1; i <= n; i++)
    {
        for (auto it : a[i])
        {
            int to = it.to;
            if (dis[to] >= d)
            {
                if (dis[to] == d)
                {
                    viss[to] = 1;
                }
                continue;
            }
            b[i].push_back({to, d - dis[to]});
        }
    }
    dij(a, n);
    sum[0] = 0;
    int now = d;
    for (int i = 1; i <= n; i++)
    {
        sum[i] = sum[i - 1] + now;
        now--;
        if (now <= 0)
            now = d;
    }
    for (int i = 1; i <= n; i++)
    {
        if (dis[i] < inf)
            w[i] = sum[dis[i]];
        else
            w[i] = inf;
    }
    int ans = inf;

    dij(b, 1);
    ans = min(ans, dis[n]);
    for (int i = 1; i <= n; i++)
    {
        if (viss[i])
        {
            ans = min(ans, dis[i] + w[i]);
        }
    }
    cout << ans << '\n';
}

void dij(vector<vector<info>> &e, int st)
{
    for (int i = 1; i <= n; i++)
    {
        vis[i] = 0;
        dis[i] = inf;
    }

    dis[st] = 0;
    priority_queue<node, vector<node>, greater<node>> q;
    q.push({dis[st], st});

    while (!q.empty())
    {
        int x = q.top().u;
        q.pop();

        if (vis[x])
            continue;
        vis[x] = 1;

        for (auto it : e[x])
        {
            int u = it.to, w = it.w;

            if (dis[u] > dis[x] + w)
            {
                dis[u] = dis[x] + w;
                q.push({dis[u], u});
            }
        }
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

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: 0ms
memory: 3556kb

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'