QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537492#7883. Takeout DeliveringMaxDYFWA 184ms60244kbC++233.3kb2024-08-30 14:21:342024-08-30 14:21:35

Judging History

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

  • [2024-08-30 14:21:35]
  • 评测
  • 测评结果:WA
  • 用时:184ms
  • 内存:60244kb
  • [2024-08-30 14:21:34]
  • 提交

answer

// #pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 3e5 + 10;
const int inf = 1 << 30;
const long long llinf = 1ll << 60;
const double PI = acos(-1);

#define lowbit(x) (x & -x)
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
typedef pair<ll, int> pli;
int n, m, k, q;
namespace Graph1
{
    typedef int64_t T;
    typedef std::pair<int64_t, int32_t> pli;
    std::vector<pli> to[N];
    void add(int x, int y, T val)
    {
        to[x].push_back({val, y});
    }
    bool vis[N];
    T dis[N];
    void shortest_path(int32_t from)
    {
        // using Dijkstra
        std::priority_queue<pli, std::vector<pli>, std::greater<pli>> q;
        q.push(std::make_pair(0, from));
        memset(dis, 0x3f, sizeof dis);
        memset(vis, 0, sizeof vis);
        dis[from] = 0;
        while (!q.empty())
        {
            auto [nowval, x] = q.top();
            q.pop();
            if (vis[x])
                continue;
            vis[x] = 1;
            for (auto [val, y] : to[x])
                if (dis[y] > dis[x] + val)
                {
                    dis[y] = dis[x] + val;
                    q.push(std::make_pair(dis[y], y));
                }
        }
    }
}
namespace Graph2
{
    typedef int64_t T;
    typedef std::pair<int64_t, int32_t> pli;
    std::vector<pli> to[N];
    void add(int x, int y, T val)
    {
        to[x].push_back({val, y});
    }
    bool vis[N];
    T dis[N];
    void shortest_path(int32_t from)
    {
        // using Dijkstra
        std::priority_queue<pli, std::vector<pli>, std::greater<pli>> q;
        q.push(std::make_pair(0, from));
        memset(dis, 0x3f, sizeof dis);
        memset(vis, 0, sizeof vis);
        dis[from] = 0;
        while (!q.empty())
        {
            auto [nowval, x] = q.top();
            q.pop();
            if (vis[x])
                continue;
            vis[x] = 1;
            for (auto [val, y] : to[x])
                if (dis[y] > max(dis[x], val))
                {
                    dis[y] = max(dis[x], val);
                    q.push(std::make_pair(dis[y], y));
                }
        }
    }
}
void work()
{
    cin >> n >> m;
    struct Edge
    {
        int x, y, w;
        bool operator<(Edge b)
        {
            return w < b.w;
        }
    };
    vector<Edge> vec;
    for (int i = 0; i < m; i++)
    {
        int x, y, v;
        cin >> x >> y >> v;
        Graph1::add(x, y, v);
        Graph1::add(y, x, v);
        Graph2::add(x, y, v);
        Graph2::add(y, x, v);
        vec.push_back(Edge{x, y, v});
    }
    Graph1::shortest_path(1);
    Graph2::shortest_path(n);
    int ans = 2e9;
    for (auto [x, y, w] : vec)
    {
        int max1 = max(Graph1::dis[x], Graph2::dis[y]);
        int max2 = max(Graph2::dis[x], Graph1::dis[y]);
        if (max1 <= w)
            ans = min(ans, max1 + w);
        if (max2 <= w)
            ans = min(ans, max2 + w);
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t-- > 0)
    {
        work();
    }
}

详细

Test #1:

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

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 184ms
memory: 60244kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

2000000000

result:

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