답안 #261363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261363 2020-08-11T16:36:51 Z Berted Aesthetic (NOI20_aesthetic) C++14
100 / 100
637 ms 56148 KB
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <bitset>
#define ll long long
#define vi vector<int>
#define pii pair<ll, int>
#define fst first
#define snd second
#define pub push_back
#define vpi vector<pii>
 
using namespace std;
 
namespace fastIO
{
	char outString[64];
	inline int getchar_unlocked() {return getchar();}
	inline void putchar_unlocked(int x) {putchar(x);}
	inline int charInput() {return getchar_unlocked();}
	inline void charOutput(int x) {putchar_unlocked(x);}
	inline bool isNum(int c) {return '0' <= c && c <= '9';}
	inline int intInput()
	{
		int c = 0, ret = 0; bool neg = 0;
		while (!isNum(c)) 
		{
			c = getchar_unlocked();
			if (c == '-') {neg = 1;}
		}
		while (isNum(c)) {ret = ret * 10 + c - '0'; c = getchar_unlocked();}
		return (neg) ? -ret : ret;
	}
	inline void intOutput(ll x)
	{
		int ss = 0;
		while (x) {outString[ss++] = x % 10 + '0'; x /= 10;}
		if (!ss) outString[ss++] = '0';
		for (int i = ss - 1; i >= 0; i--) putchar_unlocked(outString[i]);
	}
	inline void strOutput(string s)
	{
		for (auto &c : s) putchar_unlocked(c);
	}
}
 
const ll INF = 1e17;
 
int n, m, pref[300069], cst[300069], idx = 0, vis[300069], low[300069], pid = 0;
vpi adj[300069];
pii edge[300069];
ll dst[2][300069], de[2][300069], lim;
priority_queue<pii, vector<pii>, greater<pii>> pq;
bool bt[300069];
bool ans = 0;
 
inline void runDijkstra(int s, int id)
{
	for (int i = 0; i < n; i++) {dst[id][i] = INF; bt[i] = 0;}
	dst[id][s] = 0; 
	pq.emplace(0, s);
	while (pq.size())
	{
		int u = pq.top().snd; pq.pop();
		if (!bt[u])
		{
			bt[u] = 1;
			for (auto v : adj[u])
			{
				if (dst[id][u] + cst[v.fst] < dst[id][v.snd])
				{
					dst[id][v.snd] = dst[id][u] + cst[v.fst];
					pq.emplace(dst[id][v.snd], v.snd);
				}
			}
		}
	}
}
 
void bCheck(int u, int p)
{		
	vis[u] = low[u] = idx++;
	//cout << "Visit : " << idx << "\n";
	for (auto v : adj[u])
	{
		if (v.snd != p && de[0][v.fst] <= lim)
		{
			if (vis[v.snd] < pid)
			{
				bCheck(v.snd, u);
				if (ans) return;
				low[u] = min(low[v.snd], low[u]);
				if (low[v.snd] > vis[u] && (vis[n - 1] >= pid && low[v.snd] <= vis[n - 1]) && de[1][v.fst] > lim) {ans = 1; return;}
			}
			else low[u] = min(vis[v.snd], low[u]);
		}
	}
}
 
int32_t main()
{
	// ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("5-1.in", "r", stdin);
	n = fastIO :: intInput();
	m = fastIO :: intInput();
	for (int i = 0; i < n; i++) vis[i] = -1;
	for (int i = 0; i < m; i++)
	{
		int u, v, w; 
		
		u = fastIO :: intInput();
		v = fastIO :: intInput();
		w = fastIO :: intInput();
 
		u--; v--;
		adj[u].emplace_back(i, v);
		adj[v].emplace_back(i, u);
		cst[i] = pref[i] = w;
		edge[i] = {u, v};
	}
	for (int i = m - 2; i >= 0; i--) {pref[i] = max(pref[i], pref[i + 1]);}
	runDijkstra(0, 0);
	runDijkstra(n - 1, 1);
	for (int i = 0; i < m; i++) 
	{
		de[0][i] = min(dst[0][edge[i].fst] + dst[1][edge[i].snd], dst[1][edge[i].fst] + dst[0][edge[i].snd]) + cst[i];
		de[1][i] = de[0][i] + pref[i + 1];
	}
	// cout << "Dijkstra done\n";
	ll L = dst[0][n - 1], R = dst[0][n - 1] + pref[0];
	while (L < R)
	{
		ll M = L + R >> 1; lim = M; ans = 0; pid = idx;
		bCheck(0, -1);
		if (ans) L = M + 1;
		else R = M;
	}
	fastIO :: intOutput(L);
	fastIO :: charOutput('\n');
	return 0;
}

Compilation message

Aesthetic.cpp: In function 'int32_t main()':
Aesthetic.cpp:134:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   ll M = L + R >> 1; lim = M; ans = 0; pid = idx;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 6 ms 7424 KB Output is correct
4 Correct 7 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 6 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 6 ms 7424 KB Output is correct
4 Correct 7 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 6 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 7 ms 7680 KB Output is correct
11 Correct 7 ms 7680 KB Output is correct
12 Correct 10 ms 7680 KB Output is correct
13 Correct 7 ms 7680 KB Output is correct
14 Correct 7 ms 7680 KB Output is correct
15 Correct 7 ms 7680 KB Output is correct
16 Correct 7 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 621 ms 42232 KB Output is correct
2 Correct 637 ms 42360 KB Output is correct
3 Correct 634 ms 42328 KB Output is correct
4 Correct 620 ms 42048 KB Output is correct
5 Correct 577 ms 42264 KB Output is correct
6 Correct 610 ms 42876 KB Output is correct
7 Correct 599 ms 42744 KB Output is correct
8 Correct 619 ms 43000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 43260 KB Output is correct
2 Correct 600 ms 42528 KB Output is correct
3 Correct 618 ms 42108 KB Output is correct
4 Correct 600 ms 42276 KB Output is correct
5 Correct 583 ms 42280 KB Output is correct
6 Correct 593 ms 42260 KB Output is correct
7 Correct 588 ms 42360 KB Output is correct
8 Correct 615 ms 42744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 40188 KB Output is correct
2 Correct 189 ms 43900 KB Output is correct
3 Correct 294 ms 47352 KB Output is correct
4 Correct 296 ms 47352 KB Output is correct
5 Correct 289 ms 47224 KB Output is correct
6 Correct 291 ms 47352 KB Output is correct
7 Correct 295 ms 47352 KB Output is correct
8 Correct 317 ms 47652 KB Output is correct
9 Correct 317 ms 47232 KB Output is correct
10 Correct 319 ms 47736 KB Output is correct
11 Correct 333 ms 47608 KB Output is correct
12 Correct 549 ms 44780 KB Output is correct
13 Correct 319 ms 47440 KB Output is correct
14 Correct 150 ms 51832 KB Output is correct
15 Correct 126 ms 51960 KB Output is correct
16 Correct 543 ms 44976 KB Output is correct
17 Correct 455 ms 44008 KB Output is correct
18 Correct 480 ms 44564 KB Output is correct
19 Correct 208 ms 43896 KB Output is correct
20 Correct 189 ms 43896 KB Output is correct
21 Correct 187 ms 43896 KB Output is correct
22 Correct 190 ms 43896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 40188 KB Output is correct
2 Correct 189 ms 43900 KB Output is correct
3 Correct 294 ms 47352 KB Output is correct
4 Correct 296 ms 47352 KB Output is correct
5 Correct 289 ms 47224 KB Output is correct
6 Correct 291 ms 47352 KB Output is correct
7 Correct 295 ms 47352 KB Output is correct
8 Correct 317 ms 47652 KB Output is correct
9 Correct 317 ms 47232 KB Output is correct
10 Correct 319 ms 47736 KB Output is correct
11 Correct 333 ms 47608 KB Output is correct
12 Correct 549 ms 44780 KB Output is correct
13 Correct 319 ms 47440 KB Output is correct
14 Correct 150 ms 51832 KB Output is correct
15 Correct 126 ms 51960 KB Output is correct
16 Correct 543 ms 44976 KB Output is correct
17 Correct 455 ms 44008 KB Output is correct
18 Correct 480 ms 44564 KB Output is correct
19 Correct 208 ms 43896 KB Output is correct
20 Correct 189 ms 43896 KB Output is correct
21 Correct 187 ms 43896 KB Output is correct
22 Correct 190 ms 43896 KB Output is correct
23 Correct 564 ms 45564 KB Output is correct
24 Correct 232 ms 44024 KB Output is correct
25 Correct 288 ms 43380 KB Output is correct
26 Correct 277 ms 42872 KB Output is correct
27 Correct 288 ms 42872 KB Output is correct
28 Correct 287 ms 43768 KB Output is correct
29 Correct 285 ms 42872 KB Output is correct
30 Correct 297 ms 43160 KB Output is correct
31 Correct 341 ms 43512 KB Output is correct
32 Correct 303 ms 42872 KB Output is correct
33 Correct 305 ms 43640 KB Output is correct
34 Correct 559 ms 44900 KB Output is correct
35 Correct 324 ms 43256 KB Output is correct
36 Correct 140 ms 54740 KB Output is correct
37 Correct 149 ms 55508 KB Output is correct
38 Correct 505 ms 45036 KB Output is correct
39 Correct 489 ms 44388 KB Output is correct
40 Correct 538 ms 45544 KB Output is correct
41 Correct 226 ms 44024 KB Output is correct
42 Correct 225 ms 43952 KB Output is correct
43 Correct 232 ms 43936 KB Output is correct
44 Correct 226 ms 44152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 6 ms 7424 KB Output is correct
4 Correct 7 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 6 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 7 ms 7680 KB Output is correct
11 Correct 7 ms 7680 KB Output is correct
12 Correct 10 ms 7680 KB Output is correct
13 Correct 7 ms 7680 KB Output is correct
14 Correct 7 ms 7680 KB Output is correct
15 Correct 7 ms 7680 KB Output is correct
16 Correct 7 ms 7680 KB Output is correct
17 Correct 621 ms 42232 KB Output is correct
18 Correct 637 ms 42360 KB Output is correct
19 Correct 634 ms 42328 KB Output is correct
20 Correct 620 ms 42048 KB Output is correct
21 Correct 577 ms 42264 KB Output is correct
22 Correct 610 ms 42876 KB Output is correct
23 Correct 599 ms 42744 KB Output is correct
24 Correct 619 ms 43000 KB Output is correct
25 Correct 617 ms 43260 KB Output is correct
26 Correct 600 ms 42528 KB Output is correct
27 Correct 618 ms 42108 KB Output is correct
28 Correct 600 ms 42276 KB Output is correct
29 Correct 583 ms 42280 KB Output is correct
30 Correct 593 ms 42260 KB Output is correct
31 Correct 588 ms 42360 KB Output is correct
32 Correct 615 ms 42744 KB Output is correct
33 Correct 491 ms 40188 KB Output is correct
34 Correct 189 ms 43900 KB Output is correct
35 Correct 294 ms 47352 KB Output is correct
36 Correct 296 ms 47352 KB Output is correct
37 Correct 289 ms 47224 KB Output is correct
38 Correct 291 ms 47352 KB Output is correct
39 Correct 295 ms 47352 KB Output is correct
40 Correct 317 ms 47652 KB Output is correct
41 Correct 317 ms 47232 KB Output is correct
42 Correct 319 ms 47736 KB Output is correct
43 Correct 333 ms 47608 KB Output is correct
44 Correct 549 ms 44780 KB Output is correct
45 Correct 319 ms 47440 KB Output is correct
46 Correct 150 ms 51832 KB Output is correct
47 Correct 126 ms 51960 KB Output is correct
48 Correct 543 ms 44976 KB Output is correct
49 Correct 455 ms 44008 KB Output is correct
50 Correct 480 ms 44564 KB Output is correct
51 Correct 208 ms 43896 KB Output is correct
52 Correct 189 ms 43896 KB Output is correct
53 Correct 187 ms 43896 KB Output is correct
54 Correct 190 ms 43896 KB Output is correct
55 Correct 564 ms 45564 KB Output is correct
56 Correct 232 ms 44024 KB Output is correct
57 Correct 288 ms 43380 KB Output is correct
58 Correct 277 ms 42872 KB Output is correct
59 Correct 288 ms 42872 KB Output is correct
60 Correct 287 ms 43768 KB Output is correct
61 Correct 285 ms 42872 KB Output is correct
62 Correct 297 ms 43160 KB Output is correct
63 Correct 341 ms 43512 KB Output is correct
64 Correct 303 ms 42872 KB Output is correct
65 Correct 305 ms 43640 KB Output is correct
66 Correct 559 ms 44900 KB Output is correct
67 Correct 324 ms 43256 KB Output is correct
68 Correct 140 ms 54740 KB Output is correct
69 Correct 149 ms 55508 KB Output is correct
70 Correct 505 ms 45036 KB Output is correct
71 Correct 489 ms 44388 KB Output is correct
72 Correct 538 ms 45544 KB Output is correct
73 Correct 226 ms 44024 KB Output is correct
74 Correct 225 ms 43952 KB Output is correct
75 Correct 232 ms 43936 KB Output is correct
76 Correct 226 ms 44152 KB Output is correct
77 Correct 548 ms 48204 KB Output is correct
78 Correct 415 ms 46228 KB Output is correct
79 Correct 452 ms 49784 KB Output is correct
80 Correct 384 ms 49528 KB Output is correct
81 Correct 402 ms 49560 KB Output is correct
82 Correct 399 ms 49400 KB Output is correct
83 Correct 434 ms 49916 KB Output is correct
84 Correct 404 ms 50168 KB Output is correct
85 Correct 474 ms 49912 KB Output is correct
86 Correct 446 ms 49656 KB Output is correct
87 Correct 394 ms 49912 KB Output is correct
88 Correct 558 ms 47464 KB Output is correct
89 Correct 397 ms 50040 KB Output is correct
90 Correct 271 ms 55380 KB Output is correct
91 Correct 277 ms 56148 KB Output is correct
92 Correct 571 ms 47740 KB Output is correct
93 Correct 568 ms 47208 KB Output is correct
94 Correct 545 ms 46568 KB Output is correct
95 Correct 413 ms 46456 KB Output is correct
96 Correct 419 ms 46328 KB Output is correct
97 Correct 418 ms 46380 KB Output is correct
98 Correct 457 ms 46328 KB Output is correct