// 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;
}
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
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
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
UR999’s got all the games you need! Get your game on mate. Check it here: ur999
Ready for some bingo? Bingopattilogin is so easy to get into! Ready to win the prize! bingopattilogin
24betcasino’s pretty decent. Worth a look if you’re after something new. Have a go at it: 24betcasino
The bonuses here are legit and the registration process took me less than two minutes. Really impressed with the speed. iny7777
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.
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
Finally found a site that doesn’t lag during peak hours. The user experience is top notch and very intuitive. Give krwinzcasino a go
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.
Very reliable and transparent with their rules. It is refreshing to find a site that treats players fairly. My choice is phjilimk.
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.