| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 623208 | thanh913 | Ferries (NOI13_ferries) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
//types
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define pw2(x) (1LL << x)
#define getBit(x, y) (x & (1LL << y))
template <class X, class Y>
bool cmax(X &a, const Y &b) {
    return a < b ? a = b, 1 : 0;
}
template <class X, class Y>
bool cmin(X &a, const Y &b) {
    return a > b ? a = b, 1 : 0;
}
//lowercase 31, all 53
//(P/Q) % M = (P % M) * (Q^(M-2) % M)
//-------------------------------------------------------
const ld PI = 3.14159265359;
const ll mx = 3e5+5, mod = 1e9+7;
bool vs[mx];
ll n, m, f[mx];
vector<pll> adj[mx];
void dfs(int u) {
	vs[u] = true;
	vector<ll> ed;
	for (auto e : adj[u]) {
		ll v, w;
		tie(w, v) = e;
		if (vs[v]) {
			ed.push_back(f[v]);
			continue;
		}
		dfs(v);
		ed.push_back(f[v]);
	}
	sort(ed.begin(), ed.end(), greater<ll>());
	for (int i = 0; i < ed.size(); i++) {
		cmin(f[u], adj[u][i].fi + ed[i]);
	}
}
/*
f[i] : kcnn tu dinh i den n
dfs den u
trong cac canh di tu u -> v
*/
main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // freopen("Ferry.Inp", "r", stdin);
    // freopen("Ferry.Out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
    	int u, v, w;
    	cin >> u >> v >> w;
    	adj[u].push_back({w, v});
    }
    for (int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());
    
    memset(f, inf, sizeof(f));
	f[n] = 0;
    dfs(1);
	cout << f[1];
}
