QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537500#7883. Takeout DeliveringMaxDYFWA 155ms41244kbC++233.2kb2024-08-30 14:28:122024-08-30 14:28:12

Judging History

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

  • [2024-08-30 14:28:12]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:41244kb
  • [2024-08-30 14:28:12]
  • 提交

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;
int n, m, k, q;
typedef int64_t T;
typedef std::pair<int64_t, int32_t> pli;
std::vector<pli> to[N];
namespace Graph1
{
    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));
                }
        }
    }
}
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);
        vec.push_back(Edge{x, y, v});
    }
    Graph1::shortest_path(1);
    Graph2::shortest_path(n);
    ll ans = llinf;
    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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 11720kb

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: 155ms
memory: 41244kb

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:

1152921504606846976

result:

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