답안 #261354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261354 2020-08-11T16:31:08 Z Berted Aesthetic (NOI20_aesthetic) C++14
35 / 100
2000 ms 54124 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, yes[2][300069];
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 && yes[0][v.fst])
		{
			if (vis[v.snd] < pid)
			{
				bCheck(v.snd, u);
				if (ans) return;
				low[u] = min(low[v.snd], low[u]);
			}
			else low[u] = min(vis[v.snd], low[u]);
			
			if (low[v.snd] > vis[u] && (vis[n - 1] >= pid && low[v.snd] <= vis[n - 1]) && yes[1][v.fst]) {ans = 1; return;}
		}
	}
}
 
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] + 1000000000;
	while (L < R)
	{
		ll M = L + R >> 1; lim = M; ans = 0; pid = idx;
		for (int i = 0; i < m; i++)
		{
			yes[0][i] = (de[0][i] <= lim);
			yes[1][i] = (de[1][i] > lim);
		}
		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:135: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 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 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 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 8 ms 7680 KB Output is correct
11 Correct 7 ms 7680 KB Output is correct
12 Correct 7 ms 7680 KB Output is correct
13 Correct 7 ms 7680 KB Output is correct
14 Correct 6 ms 7680 KB Output is correct
15 Correct 7 ms 7680 KB Output is correct
16 Correct 6 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 608 ms 46804 KB Output is correct
2 Correct 599 ms 46968 KB Output is correct
3 Correct 611 ms 46972 KB Output is correct
4 Correct 646 ms 46840 KB Output is correct
5 Correct 652 ms 47224 KB Output is correct
6 Correct 579 ms 47968 KB Output is correct
7 Correct 588 ms 47668 KB Output is correct
8 Correct 674 ms 47992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 679 ms 47900 KB Output is correct
2 Correct 538 ms 47352 KB Output is correct
3 Correct 558 ms 46928 KB Output is correct
4 Correct 607 ms 47352 KB Output is correct
5 Correct 537 ms 47224 KB Output is correct
6 Correct 620 ms 47224 KB Output is correct
7 Correct 606 ms 47244 KB Output is correct
8 Correct 604 ms 47480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2092 ms 54124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2092 ms 54124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 8 ms 7680 KB Output is correct
11 Correct 7 ms 7680 KB Output is correct
12 Correct 7 ms 7680 KB Output is correct
13 Correct 7 ms 7680 KB Output is correct
14 Correct 6 ms 7680 KB Output is correct
15 Correct 7 ms 7680 KB Output is correct
16 Correct 6 ms 7680 KB Output is correct
17 Correct 608 ms 46804 KB Output is correct
18 Correct 599 ms 46968 KB Output is correct
19 Correct 611 ms 46972 KB Output is correct
20 Correct 646 ms 46840 KB Output is correct
21 Correct 652 ms 47224 KB Output is correct
22 Correct 579 ms 47968 KB Output is correct
23 Correct 588 ms 47668 KB Output is correct
24 Correct 674 ms 47992 KB Output is correct
25 Correct 679 ms 47900 KB Output is correct
26 Correct 538 ms 47352 KB Output is correct
27 Correct 558 ms 46928 KB Output is correct
28 Correct 607 ms 47352 KB Output is correct
29 Correct 537 ms 47224 KB Output is correct
30 Correct 620 ms 47224 KB Output is correct
31 Correct 606 ms 47244 KB Output is correct
32 Correct 604 ms 47480 KB Output is correct
33 Execution timed out 2092 ms 54124 KB Time limit exceeded
34 Halted 0 ms 0 KB -