Submission #475781

# Submission time Handle Problem Language Result Execution time Memory
475781 2021-09-24T04:36:40 Z maomao90 Aesthetic (NOI20_aesthetic) C++17
35 / 100
2000 ms 56872 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) printf(args)
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 300005

struct edge {
	int v, w, p;
};

int n, m;
vector<edge> adj[MAXN];
int a[MAXN], b[MAXN], w[MAXN], p[MAXN];
ll base;

priority_queue<pll, vector<pll>, greater<pll>> pq;
ll d1[MAXN], dn[MAXN];
void dij(int s, ll* d) {
	REP (i, 1, n + 1) {
		d[i] = LINF;
	}
	d[s] = 0;
	pq.push(MP(0, s));
	while (!pq.empty()) {
		auto [ud, u] = pq.top(); pq.pop();
		if (ud != d[u]) continue;
		for (edge e : adj[u]) {
			if (mnto(d[e.v], ud + e.w)) {
				pq.push(MP(d[e.v], e.v));
			}
		}
	}
}

ll x;
bool res;
int pre[MAXN], top[MAXN], ptr;
vector<edge> nadj[MAXN];
void dfs(int u, int p) {
	pre[u] = top[u] = ptr++;
	for (edge e : nadj[u]) {
		if (e.v == p) continue;
		if (pre[e.v] == -1) {
			dfs(e.v, u);
			mnto(top[u], top[e.v]);
			if (top[e.v] > pre[u]) {
				if ((min(d1[u] + dn[e.v], d1[e.v] + dn[u])
					   	+ e.w + e.p > x + base) && 
						pre[n] != -1 && 
						pre[n] >= top[e.v])	{
					res = 1;
				}
			}
		} else {
			mnto(top[u], pre[e.v]);
		}
	}
}

bool isPos(ll x) {
	REP (i, 1, n + 1) {
		nadj[i].clear();
	}
	debug("%lld\n", x);
	REP (i, 0, m) {
		if (min(d1[a[i]] + dn[b[i]], d1[b[i]] + dn[a[i]]) + w[i] <= x + base) {
			debug(" %d %d %d\n", a[i], b[i], p[i]);
			debug("  %lld + %d + %d\n", min(d1[a[i]] + dn[b[i]], d1[b[i]] + dn[a[i]]), w[i], p[i]);
			nadj[a[i]].pb({b[i], w[i], p[i]});
			nadj[b[i]].pb({a[i], w[i], p[i]});
		}
	}
	ptr = 0;
	::x = x;
	res = 0;
	memset(pre, -1, sizeof pre);
	REP (i, 1, n + 1) {
		if (pre[i] == -1) {
			dfs(i, -1);
		}
	}
	return res;
}

int main() {
	scanf("%d%d", &n, &m);
	REP (i, 0, m) {
		scanf("%d%d%d", &a[i], &b[i], &w[i]);
	}
	int mx = 0;
	RREP (i, m - 1, 0) {
		p[i] = mx;
		mxto(mx, w[i]);
	}
	REP (i, 0, m) {
		adj[a[i]].pb({b[i], w[i], p[i]});
		adj[b[i]].pb({a[i], w[i], p[i]});
	}
	dij(1, d1);
	dij(n, dn);
	base = d1[n];
	ll lo = 0, hi = INF, mid;
	while (lo < hi) {
		mid = lo + hi + 1 >> 1;
		if (isPos(mid)) {
			lo = mid;
		} else {
			hi = mid - 1;
		}
	}
	printf("%lld\n", base + lo + 1);
	return 0;
}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:133:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  133 |   mid = lo + hi + 1 >> 1;
      |         ~~~~~~~~^~~
Aesthetic.cpp:115:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
Aesthetic.cpp:117:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |   scanf("%d%d%d", &a[i], &b[i], &w[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15564 KB Output is correct
2 Correct 11 ms 15564 KB Output is correct
3 Correct 9 ms 15564 KB Output is correct
4 Correct 11 ms 15552 KB Output is correct
5 Correct 10 ms 15564 KB Output is correct
6 Correct 11 ms 15672 KB Output is correct
7 Correct 10 ms 15560 KB Output is correct
8 Correct 10 ms 15564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15564 KB Output is correct
2 Correct 11 ms 15564 KB Output is correct
3 Correct 9 ms 15564 KB Output is correct
4 Correct 11 ms 15552 KB Output is correct
5 Correct 10 ms 15564 KB Output is correct
6 Correct 11 ms 15672 KB Output is correct
7 Correct 10 ms 15560 KB Output is correct
8 Correct 10 ms 15564 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 14 ms 15696 KB Output is correct
11 Correct 11 ms 15692 KB Output is correct
12 Correct 12 ms 15692 KB Output is correct
13 Correct 11 ms 15820 KB Output is correct
14 Correct 13 ms 15824 KB Output is correct
15 Correct 11 ms 15824 KB Output is correct
16 Correct 13 ms 15820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 644 ms 38540 KB Output is correct
2 Correct 665 ms 38592 KB Output is correct
3 Correct 579 ms 38340 KB Output is correct
4 Correct 585 ms 38348 KB Output is correct
5 Correct 630 ms 38468 KB Output is correct
6 Correct 623 ms 39044 KB Output is correct
7 Correct 585 ms 38712 KB Output is correct
8 Correct 574 ms 39056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 39064 KB Output is correct
2 Correct 587 ms 38728 KB Output is correct
3 Correct 601 ms 38580 KB Output is correct
4 Correct 567 ms 38932 KB Output is correct
5 Correct 632 ms 38520 KB Output is correct
6 Correct 566 ms 38636 KB Output is correct
7 Correct 582 ms 38668 KB Output is correct
8 Correct 627 ms 38648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2078 ms 56872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2078 ms 56872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15564 KB Output is correct
2 Correct 11 ms 15564 KB Output is correct
3 Correct 9 ms 15564 KB Output is correct
4 Correct 11 ms 15552 KB Output is correct
5 Correct 10 ms 15564 KB Output is correct
6 Correct 11 ms 15672 KB Output is correct
7 Correct 10 ms 15560 KB Output is correct
8 Correct 10 ms 15564 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 14 ms 15696 KB Output is correct
11 Correct 11 ms 15692 KB Output is correct
12 Correct 12 ms 15692 KB Output is correct
13 Correct 11 ms 15820 KB Output is correct
14 Correct 13 ms 15824 KB Output is correct
15 Correct 11 ms 15824 KB Output is correct
16 Correct 13 ms 15820 KB Output is correct
17 Correct 644 ms 38540 KB Output is correct
18 Correct 665 ms 38592 KB Output is correct
19 Correct 579 ms 38340 KB Output is correct
20 Correct 585 ms 38348 KB Output is correct
21 Correct 630 ms 38468 KB Output is correct
22 Correct 623 ms 39044 KB Output is correct
23 Correct 585 ms 38712 KB Output is correct
24 Correct 574 ms 39056 KB Output is correct
25 Correct 619 ms 39064 KB Output is correct
26 Correct 587 ms 38728 KB Output is correct
27 Correct 601 ms 38580 KB Output is correct
28 Correct 567 ms 38932 KB Output is correct
29 Correct 632 ms 38520 KB Output is correct
30 Correct 566 ms 38636 KB Output is correct
31 Correct 582 ms 38668 KB Output is correct
32 Correct 627 ms 38648 KB Output is correct
33 Execution timed out 2078 ms 56872 KB Time limit exceeded
34 Halted 0 ms 0 KB -