답안 #302377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302377 2020-09-18T16:08:29 Z errorgorn Aesthetic (NOI20_aesthetic) C++14
51 / 100
2000 ms 52852 KB
//雪花飄飄北風嘯嘯

//天地一片蒼茫



#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope>

using namespace std;

using namespace __gnu_pbds;

using namespace __gnu_cxx;

#define ll long long

#define ii pair<ll,ll>

#define iii pair<ii,ll>

#define fi first

#define se second

#define endl '\n'

#define debug(x) cout << #x << " is " << x << endl;



#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))

#define all(x) (x).begin(),(x).end()

#define sz(x) (int)(x).size()



ll MAX(ll a){return a;}

ll MIN(ll a){return a;}

template<typename... Args>

ll MAX(ll a,Args... args){return max(a,MAX(args...));}

template<typename... Args>

ll MIN(ll a,Args... args){return min(a,MIN(args...));}



#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>



mt19937 rng(chrono::system_clock::now().time_since_epoch().count());



int n,m;

vector<ii> al[300005];

ii edge[300005];

ll w[300005];

ll p[300005];



ll fw[300005]; //dist 1->i

ll bw[300005]; //dist N->i



priority_queue<ii,vector<ii>,greater<ii> > pq;



bool used[300005];



int TIME;

int in[300005];

int low[300005];

bool dc[300005]; //whether will disconnect vertice 1 and N



vector<int> bridge;



void dfs(int i,int p){

	in[i]=low[i]=TIME++;

	if (i==n) dc[i]=true;

	

	for (auto &it:al[i]){

		if (it.fi==p || !used[it.se]) continue;

		

		if (!in[it.fi]){

			dfs(it.fi,i);

			low[i]=min(low[i],low[it.fi]);

			if (dc[it.fi]){

				if (in[it.fi]==low[it.fi]) bridge.push_back(it.se);

				dc[i]=true;

			}

		}

		else{

			low[i]=min(low[i],in[it.fi]);

		}

	}

}



bool test(ll i){

	if (i<fw[n]) return true;

	

	rep(x,0,m){

		used[x]=(fw[edge[x].fi]+w[x]+bw[edge[x].se]<=i || 

				 fw[edge[x].se]+w[x]+bw[edge[x].fi]<=i);

	}

	

	TIME=1;

	bridge.clear();

	memset(in,0,sizeof(in));

	memset(dc,false,sizeof(dc));

	dfs(1,-1);

	

	for (auto &it:bridge){

		if (fw[edge[it].fi]+w[it]+p[it]+bw[edge[it].se]>i &&

			fw[edge[it].se]+w[it]+p[it]+bw[edge[it].fi]>i) return true;

	}

	

	return false;

}



int main(){

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	

	cin>>n>>m;

	

	rep(x,0,m){

		cin>>edge[x].fi>>edge[x].se>>w[x];

		

		al[edge[x].fi].push_back(ii(edge[x].se,x));

		al[edge[x].se].push_back(ii(edge[x].fi,x));

	}

	

	rep(x,m,0) p[x]=max(p[x+1],w[x+1]);

	

	memset(fw,63,sizeof(fw));

	fw[1]=0;

	pq.push(ii(fw[1],1));

	while (!pq.empty()){

		ll node=pq.top().se,weight=pq.top().fi;

		pq.pop();

		

		if (fw[node]!=weight) continue;

		for (auto &it:al[node]){

			if (fw[it.fi]>weight+w[it.se]){

				fw[it.fi]=weight+w[it.se];

				if (it.fi!=n) pq.push(ii(fw[it.fi],it.fi));

			}

		}

	}

	

	memset(bw,63,sizeof(bw));

	bw[n]=0;

	pq.push(ii(bw[n],n));

	while (!pq.empty()){

		ll node=pq.top().se,weight=pq.top().fi;

		pq.pop();

		

		if (bw[node]!=weight) continue;

		for (auto &it:al[node]){

			if (bw[it.fi]>weight+w[it.se]){

				bw[it.fi]=weight+w[it.se];

				if (it.fi!=1) pq.push(ii(bw[it.fi],it.fi));

			}

		}

	}

	

	ll lo=fw[n]-1,hi=fw[n]+1e9+10,mi;

	

	while (hi-lo>1){

		mi=hi+lo>>1;

		

		if (test(mi)) lo=mi;

		else hi=mi;

	}

	

	cout<<hi<<endl;

}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:295:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  295 |   mi=hi+lo>>1;
      |      ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 13568 KB Output is correct
2 Correct 10 ms 13568 KB Output is correct
3 Correct 10 ms 13568 KB Output is correct
4 Correct 11 ms 13568 KB Output is correct
5 Correct 13 ms 13568 KB Output is correct
6 Correct 13 ms 13568 KB Output is correct
7 Correct 13 ms 13568 KB Output is correct
8 Correct 10 ms 13568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 13568 KB Output is correct
2 Correct 10 ms 13568 KB Output is correct
3 Correct 10 ms 13568 KB Output is correct
4 Correct 11 ms 13568 KB Output is correct
5 Correct 13 ms 13568 KB Output is correct
6 Correct 13 ms 13568 KB Output is correct
7 Correct 13 ms 13568 KB Output is correct
8 Correct 10 ms 13568 KB Output is correct
9 Correct 12 ms 13824 KB Output is correct
10 Correct 12 ms 13824 KB Output is correct
11 Correct 13 ms 13824 KB Output is correct
12 Correct 13 ms 13824 KB Output is correct
13 Correct 12 ms 13824 KB Output is correct
14 Correct 12 ms 13824 KB Output is correct
15 Correct 12 ms 13824 KB Output is correct
16 Correct 12 ms 13824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 653 ms 40568 KB Output is correct
2 Correct 648 ms 40568 KB Output is correct
3 Correct 677 ms 40232 KB Output is correct
4 Correct 689 ms 40312 KB Output is correct
5 Correct 679 ms 40572 KB Output is correct
6 Correct 657 ms 40952 KB Output is correct
7 Correct 668 ms 40856 KB Output is correct
8 Correct 673 ms 41208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 41208 KB Output is correct
2 Correct 671 ms 40696 KB Output is correct
3 Correct 679 ms 40312 KB Output is correct
4 Correct 703 ms 40184 KB Output is correct
5 Correct 654 ms 40436 KB Output is correct
6 Correct 672 ms 40568 KB Output is correct
7 Correct 661 ms 40688 KB Output is correct
8 Correct 663 ms 40744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1971 ms 47340 KB Output is correct
2 Correct 745 ms 38392 KB Output is correct
3 Correct 1004 ms 44152 KB Output is correct
4 Correct 994 ms 44152 KB Output is correct
5 Correct 983 ms 44024 KB Output is correct
6 Correct 1016 ms 44408 KB Output is correct
7 Correct 990 ms 44152 KB Output is correct
8 Correct 1014 ms 44380 KB Output is correct
9 Correct 1000 ms 44280 KB Output is correct
10 Correct 975 ms 44664 KB Output is correct
11 Correct 1012 ms 44280 KB Output is correct
12 Correct 1917 ms 48044 KB Output is correct
13 Correct 997 ms 44500 KB Output is correct
14 Correct 344 ms 52780 KB Output is correct
15 Correct 413 ms 52852 KB Output is correct
16 Correct 1968 ms 48240 KB Output is correct
17 Correct 1949 ms 47468 KB Output is correct
18 Correct 1995 ms 47980 KB Output is correct
19 Correct 765 ms 38408 KB Output is correct
20 Correct 786 ms 38348 KB Output is correct
21 Correct 771 ms 38392 KB Output is correct
22 Correct 748 ms 38520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1971 ms 47340 KB Output is correct
2 Correct 745 ms 38392 KB Output is correct
3 Correct 1004 ms 44152 KB Output is correct
4 Correct 994 ms 44152 KB Output is correct
5 Correct 983 ms 44024 KB Output is correct
6 Correct 1016 ms 44408 KB Output is correct
7 Correct 990 ms 44152 KB Output is correct
8 Correct 1014 ms 44380 KB Output is correct
9 Correct 1000 ms 44280 KB Output is correct
10 Correct 975 ms 44664 KB Output is correct
11 Correct 1012 ms 44280 KB Output is correct
12 Correct 1917 ms 48044 KB Output is correct
13 Correct 997 ms 44500 KB Output is correct
14 Correct 344 ms 52780 KB Output is correct
15 Correct 413 ms 52852 KB Output is correct
16 Correct 1968 ms 48240 KB Output is correct
17 Correct 1949 ms 47468 KB Output is correct
18 Correct 1995 ms 47980 KB Output is correct
19 Correct 765 ms 38408 KB Output is correct
20 Correct 786 ms 38348 KB Output is correct
21 Correct 771 ms 38392 KB Output is correct
22 Correct 748 ms 38520 KB Output is correct
23 Correct 1922 ms 48356 KB Output is correct
24 Correct 803 ms 38444 KB Output is correct
25 Correct 984 ms 44024 KB Output is correct
26 Correct 942 ms 44024 KB Output is correct
27 Correct 948 ms 43996 KB Output is correct
28 Correct 983 ms 44324 KB Output is correct
29 Correct 984 ms 44280 KB Output is correct
30 Correct 950 ms 44152 KB Output is correct
31 Correct 964 ms 44536 KB Output is correct
32 Correct 948 ms 44152 KB Output is correct
33 Correct 986 ms 44432 KB Output is correct
34 Correct 1938 ms 48104 KB Output is correct
35 Correct 1018 ms 44408 KB Output is correct
36 Correct 354 ms 51300 KB Output is correct
37 Correct 400 ms 51300 KB Output is correct
38 Execution timed out 2031 ms 47908 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 13568 KB Output is correct
2 Correct 10 ms 13568 KB Output is correct
3 Correct 10 ms 13568 KB Output is correct
4 Correct 11 ms 13568 KB Output is correct
5 Correct 13 ms 13568 KB Output is correct
6 Correct 13 ms 13568 KB Output is correct
7 Correct 13 ms 13568 KB Output is correct
8 Correct 10 ms 13568 KB Output is correct
9 Correct 12 ms 13824 KB Output is correct
10 Correct 12 ms 13824 KB Output is correct
11 Correct 13 ms 13824 KB Output is correct
12 Correct 13 ms 13824 KB Output is correct
13 Correct 12 ms 13824 KB Output is correct
14 Correct 12 ms 13824 KB Output is correct
15 Correct 12 ms 13824 KB Output is correct
16 Correct 12 ms 13824 KB Output is correct
17 Correct 653 ms 40568 KB Output is correct
18 Correct 648 ms 40568 KB Output is correct
19 Correct 677 ms 40232 KB Output is correct
20 Correct 689 ms 40312 KB Output is correct
21 Correct 679 ms 40572 KB Output is correct
22 Correct 657 ms 40952 KB Output is correct
23 Correct 668 ms 40856 KB Output is correct
24 Correct 673 ms 41208 KB Output is correct
25 Correct 698 ms 41208 KB Output is correct
26 Correct 671 ms 40696 KB Output is correct
27 Correct 679 ms 40312 KB Output is correct
28 Correct 703 ms 40184 KB Output is correct
29 Correct 654 ms 40436 KB Output is correct
30 Correct 672 ms 40568 KB Output is correct
31 Correct 661 ms 40688 KB Output is correct
32 Correct 663 ms 40744 KB Output is correct
33 Correct 1971 ms 47340 KB Output is correct
34 Correct 745 ms 38392 KB Output is correct
35 Correct 1004 ms 44152 KB Output is correct
36 Correct 994 ms 44152 KB Output is correct
37 Correct 983 ms 44024 KB Output is correct
38 Correct 1016 ms 44408 KB Output is correct
39 Correct 990 ms 44152 KB Output is correct
40 Correct 1014 ms 44380 KB Output is correct
41 Correct 1000 ms 44280 KB Output is correct
42 Correct 975 ms 44664 KB Output is correct
43 Correct 1012 ms 44280 KB Output is correct
44 Correct 1917 ms 48044 KB Output is correct
45 Correct 997 ms 44500 KB Output is correct
46 Correct 344 ms 52780 KB Output is correct
47 Correct 413 ms 52852 KB Output is correct
48 Correct 1968 ms 48240 KB Output is correct
49 Correct 1949 ms 47468 KB Output is correct
50 Correct 1995 ms 47980 KB Output is correct
51 Correct 765 ms 38408 KB Output is correct
52 Correct 786 ms 38348 KB Output is correct
53 Correct 771 ms 38392 KB Output is correct
54 Correct 748 ms 38520 KB Output is correct
55 Correct 1922 ms 48356 KB Output is correct
56 Correct 803 ms 38444 KB Output is correct
57 Correct 984 ms 44024 KB Output is correct
58 Correct 942 ms 44024 KB Output is correct
59 Correct 948 ms 43996 KB Output is correct
60 Correct 983 ms 44324 KB Output is correct
61 Correct 984 ms 44280 KB Output is correct
62 Correct 950 ms 44152 KB Output is correct
63 Correct 964 ms 44536 KB Output is correct
64 Correct 948 ms 44152 KB Output is correct
65 Correct 986 ms 44432 KB Output is correct
66 Correct 1938 ms 48104 KB Output is correct
67 Correct 1018 ms 44408 KB Output is correct
68 Correct 354 ms 51300 KB Output is correct
69 Correct 400 ms 51300 KB Output is correct
70 Execution timed out 2031 ms 47908 KB Time limit exceeded
71 Halted 0 ms 0 KB -