CSES Flight Discount
// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#else
#define debug(x...) {};
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define double long double
#define int long long
#define MAXN 200010

struct graph {
    struct node {
        int u, v, w;
    };
    vector<vector<node>> e;
    int n, m;
    bool directed;
    bool weighted = 0;
    graph(int V, bool D = 0) {
        n = V;
        e.resize(n);
        directed = D;
    }
    void add_edge(int u, int v, int w = 1) {
        e[u].push_back(node{u, v, w});
        ++m;
    }
    void spfa(int s, vector<int> &dis) {
        dis.resize(n, INF);
        vector<bool> inq(n, 0);
        vector<int> cnt(n, 0);
        queue<int> q;
        dis[s] = 0, q.push(s), inq[s] = 1;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            inq[u] = 0;
            for (auto edge: e[u]) {
                int v = edge.v, w = edge.w;
                if (dis[v] > dis[u] + w && dis[v] != -INF) {
                    dis[v] = dis[u] + w;
                    cnt[v] = cnt[u] + 1;
                    if (cnt[v] > n) dis[v] = -INF;
                    if (!inq[v]) q.push(v), inq[v] = 1;
                }
            }
        }
    }
    void dijkstra(int s, vector<int> &dis) {
        dis.resize(n, INF);
        vector<bool> vis(n, 0);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
        dis[s] = 0, pq.push({0, s});
        while (!pq.empty()) {
            int u = pq.top().second; pq.pop();
            if (vis[u]) continue;
            vis[u] = 1;
            for (auto edge: e[u]) {
                int v = edge.v, w = edge.w;
                if (dis[v] > dis[u] + w) {
                    dis[v] = dis[u] + w;
                    pq.push({dis[v], v});
                }
            }
        }
    }
    void floyd(vector<vector<int>> &dis) {
        dis.resize(n, vector<int>(n, INF));
        rep(i, 0, n) dis[i][i] = 0;
        rep(u, 0, n) for (auto edge: e[u]) {
            int v = edge.v, w = edge.w;
            dis[u][v] = min(dis[u][v], w);
        }
        rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
            if (dis[i][k] == INF || dis[k][j] == INF) continue;
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        }
    }
    void graphviz_dump(string filename = "graph.dot") {
        ofstream gf;
        gf.open(filename);
        gf << (directed ? "digraph" : "graph") << " {\n";
        gf << "    "; rep(i, 0, n) gf << i << " ;"[i==n-1]; gf << endl;
        string notation = directed ? " -> " : " -- ";
        for (auto es: e) for (auto edge: es) if (edge.w != 1) weighted = 1;
        for (auto es: e) {
            for (auto edge: es) {
                if (!directed && edge.u > edge.v) continue;
                gf << "    " << edge.u << notation << edge.v << (weighted ? " ;\n" : ";\n");
            }
        }
        gf << "}\n";
    }
};
 

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, m; cin >> n >> m;
    graph g(2*n, 1);
    rep(i, 0, m) {
        int u, v, w; cin >> u >> v >> w;
        --u, --v;
        g.add_edge(u, v, w);
        g.add_edge(n + u, n + v, w);
        g.add_edge(u, n + v, w >> 1);
    }
    g.graphviz_dump();
    vector<int> dis;
    g.dijkstra(0, dis);
    cout << dis[2*n-1] << endl;

    return 0;
}

Comments

  1. 11 months ago
    2025-12-06 2:32:28

    Logged into jili666login, and the site’s running smoothly. Found a few games I like already, so I’m set for the night. Log in and play: jili666login

  2. 11 months ago
    2025-12-19 13:47:28

    Hey 123win58, what’s the scoop? Got some good games and promos going on? I’m always looking for a new spot to try my luck. Give me a reason to sign up! Play now at: 123win58

  3. 10 months ago
    2025-12-29 6:15:47

    Spinbet99vn – the name sounds fun! I’m always looking for new places to try my luck. Are the payouts good? 🤔 If so, I’m in! spinbet99vn

  4. 8 months ago
    2026-3-02 19:49:20

    UR999’s got all the games you need! Get your game on mate. Check it here: ur999

  5. 8 months ago
    2026-3-02 19:49:36

    Ready for some bingo? Bingopattilogin is so easy to get into! Ready to win the prize! bingopattilogin

  6. 8 months ago
    2026-3-02 19:49:52

    24betcasino’s pretty decent. Worth a look if you’re after something new. Have a go at it: 24betcasino

  7. 2 months ago
    2026-9-17 14:55:19

    The bonuses here are legit and the registration process took me less than two minutes. Really impressed with the speed. iny7777

  8. 1 month ago
    2026-9-20 7:31:12

    Super impressed with the graphics and the overall feel of the app. It makes the whole experience so much more immersive. I’m sticking with cl44app.

  9. 1 month ago
    2026-9-28 19:23:25

    The app interface is super smooth and the login process is a breeze. I really love how fast the games load. Definitely a great choice for anyone looking for a reliable platform. Check out 666jililoginapp

  10. 1 month ago
    2026-9-29 12:53:10

    Finally found a site that doesn’t lag during peak hours. The user experience is top notch and very intuitive. Give krwinzcasino a go

  11. 4 weeks ago
    2026-10-08 14:03:16

    I’m really enjoying the daily rewards and the community atmosphere. It’s a great place to relax and win some cash. Visit krkorwin88 and see for yourself.

  12. 2 weeks ago
    2026-10-20 7:56:36

    Very reliable and transparent with their rules. It is refreshing to find a site that treats players fairly. My choice is phjilimk.

  13. 1 week ago
    2026-10-22 21:31:48

    This place has a great community and the rewards are legit. I’ve recommended it to all my friends because it is simply the best. Visit pkpa777 and start your luck today.

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next