답안 #623209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623209 2022-08-05T10:26:27 Z thanh913 페리들 (NOI13_ferries) C++14
0 / 40
169 ms 23648 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[v].push_back({w, u});
    }
    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 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 10836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 23648 KB Output isn't correct
2 Halted 0 ms 0 KB -