답안 #623214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623214 2022-08-05T10:35:05 Z thanh913 페리들 (NOI13_ferries) C++14
28 / 40
141 ms 23772 KB
#include <bits/stdc++.h>
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];
}

Compilation message

ferries.cpp: In function 'void dfs(int)':
ferries.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for (int i = 0; i < ed.size(); i++) {
      |                  ~~^~~~~~~~~~~
ferries.cpp: At global scope:
ferries.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9812 KB Output is correct
3 Correct 12 ms 10576 KB Output is correct
4 Correct 82 ms 19312 KB Output is correct
5 Correct 91 ms 19304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 11 ms 10596 KB Output is correct
4 Correct 40 ms 14368 KB Output is correct
5 Correct 49 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 10580 KB Output is correct
2 Correct 14 ms 10956 KB Output is correct
3 Correct 139 ms 23772 KB Output is correct
4 Correct 127 ms 22480 KB Output is correct
5 Correct 117 ms 21780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 141 ms 19844 KB Output isn't correct
2 Halted 0 ms 0 KB -