답안 #677253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677253 2023-01-02T16:26:49 Z vovamr Aesthetic (NOI20_aesthetic) C++17
35 / 100
1029 ms 51640 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

#define int long long

const int N = 3e5 + 10;
const int M = 3e5 + 10;

ve<int> gr[N];

int n;

array<int,3> edges[M];
inline int go(const int &ID, const int &v) { return v ^ edges[ID][0] ^ edges[ID][1]; }

inline ve<ll> dij(const int &s) {
	ve<ll> d(n, inf); d[s] = 0;
	set<pll> st; st.insert({d[s], s});

	while (sz(st)) {
		int v = st.begin()->se;
		st.erase(st.begin());

		for (auto &id : gr[v]) {
			int to = go(id, v);
			int w = edges[id][2];

			if (d[to] > d[v] + w) {
				st.erase({d[to], to});
				d[to] = d[v] + w;
				st.insert({d[to], to});
			}
		}
	}
	return d;
}

inline void solve() {
	int m;
	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int v, u, w;
		cin >> v >> u >> w;

		edges[i] = {--v, --u, w};

		gr[v].pb(i);
		gr[u].pb(i);
	}

	ve<int> sf(m);
	for (int i = m - 2; ~i; --i) {
		sf[i] = max(sf[i + 1], edges[i + 1][2]);
	}

	auto d0 = dij(0);
	auto d1 = dij(n - 1);

	auto can = [&](const ll &x) -> bool {

		int timer = 0;
		ve<int> in(n), up(n), used(n);

		bool ok = 0;

		function<void(int,int)> dfs = [&](int v, int pid) {
			used[v] = 1;
			in[v] = up[v] = timer++;

			for (auto &id : gr[v]) {
				int to = go(id, v);

				auto &[A, B, w] = edges[id];
				ll cs = min(d0[A] + d1[B], d1[A] + d0[B]) + w;

				if (cs >= x || id == pid) continue;

				if (used[to] == 1) {
					chmin(up[v], in[to]);
				}
				else if (!used[to]) {
					dfs(to, id);
					chmin(up[v], up[to]);

					if (up[to] > in[v] && in[n - 1] >= in[to] && cs + sf[id] >= x) {
						ok = 1;
					}
				}
			}
			used[v] = 2;
		};
		dfs(0, -1);

		return ok;
	};

	ll l = d0[n - 1], r = d0[n - 1] + sf[0] + 1e3, mid, ans;
	while (l <= r) {
		mid = l + r >> 1;
		if (can(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}

Compilation message

Aesthetic.cpp: In function 'void solve()':
Aesthetic.cpp:119:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  119 |   mid = l + r >> 1;
      |         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 6 ms 7508 KB Output is correct
10 Correct 5 ms 7508 KB Output is correct
11 Correct 6 ms 7508 KB Output is correct
12 Correct 5 ms 7508 KB Output is correct
13 Correct 6 ms 7508 KB Output is correct
14 Correct 5 ms 7568 KB Output is correct
15 Correct 5 ms 7508 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 497 ms 39348 KB Output is correct
2 Correct 504 ms 39460 KB Output is correct
3 Correct 538 ms 39244 KB Output is correct
4 Correct 531 ms 39436 KB Output is correct
5 Correct 585 ms 39432 KB Output is correct
6 Correct 575 ms 40032 KB Output is correct
7 Correct 541 ms 39908 KB Output is correct
8 Correct 585 ms 40076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 604 ms 40100 KB Output is correct
2 Correct 629 ms 39580 KB Output is correct
3 Correct 493 ms 39544 KB Output is correct
4 Correct 525 ms 40012 KB Output is correct
5 Correct 528 ms 39420 KB Output is correct
6 Correct 509 ms 39528 KB Output is correct
7 Correct 543 ms 39508 KB Output is correct
8 Correct 565 ms 39768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1029 ms 51640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1029 ms 51640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 6 ms 7508 KB Output is correct
10 Correct 5 ms 7508 KB Output is correct
11 Correct 6 ms 7508 KB Output is correct
12 Correct 5 ms 7508 KB Output is correct
13 Correct 6 ms 7508 KB Output is correct
14 Correct 5 ms 7568 KB Output is correct
15 Correct 5 ms 7508 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 497 ms 39348 KB Output is correct
18 Correct 504 ms 39460 KB Output is correct
19 Correct 538 ms 39244 KB Output is correct
20 Correct 531 ms 39436 KB Output is correct
21 Correct 585 ms 39432 KB Output is correct
22 Correct 575 ms 40032 KB Output is correct
23 Correct 541 ms 39908 KB Output is correct
24 Correct 585 ms 40076 KB Output is correct
25 Correct 604 ms 40100 KB Output is correct
26 Correct 629 ms 39580 KB Output is correct
27 Correct 493 ms 39544 KB Output is correct
28 Correct 525 ms 40012 KB Output is correct
29 Correct 528 ms 39420 KB Output is correct
30 Correct 509 ms 39528 KB Output is correct
31 Correct 543 ms 39508 KB Output is correct
32 Correct 565 ms 39768 KB Output is correct
33 Incorrect 1029 ms 51640 KB Output isn't correct
34 Halted 0 ms 0 KB -