Submission #743922

# Submission time Handle Problem Language Result Execution time Memory
743922 2023-05-18T06:12:25 Z tolbi Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
template<typename X, typename Y> pair<X,Y> operator+(pair<X,Y> a, pair<X,Y> b) {pair<X,Y> c; c.first=a.first+b.first,c.second=a.second+b.second;return c;}
template<typename X, typename Y> pair<X,Y> operator-(pair<X,Y> a, pair<X,Y> b) {pair<X,Y> c; c.first=a.first-b.first,c.second=a.second-b.second;return c;}
template<typename X, typename Y> void operator+=(pair<X,Y> &a, pair<X,Y> b){a.first+=b.first,a.second+=b.second;}
template<typename X, typename Y> void operator-=(pair<X,Y> &a, pair<X,Y> b){a.first-=b.first,a.second-=b.second;}
template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename X, size_t Y> istream& operator>>(istream& in, array<X,Y> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> arr) {for(auto &it : arr) os<<it<<" "; return os;}
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
vector<vector<int>> st;
vector<vector<int>> ma;
vector<vector<int>> mi;
vector<int> dep;
vector<int> val;
vector<int> c2;
vector<int> c3;
vector<int> par;
int LOG;
int find(int node){
	if (par[node]==node) return node;
	return par[node]=find(par[node]);
}
void merge(int a, int b){
	a=find(a);
	b=find(b);
	if (ayahya()%2) swap(a,b);
	par[a]=b;
}
#include "swap.h"
int mava = 0;
bool lin = false;
void init(int32_t N, int32_t M, vector<int32_t> U, vector<int32_t> V, vector<int32_t> W) {
	if (M==N-1) lin=true;
	LOG = log2(N)+3;
	vector<pair<int,pair<int,int>>> ed(M);
	par.resize(N);
	dep.resize(N);
	val.resize(N,INF);
	c2.resize(N,INF);
	c3.resize(N,INF);
	mi.resize(N,vector<int>(LOG,INF));
	ma.resize(N,vector<int>(LOG,0));
	st.resize(N,vector<int>(LOG,-1));
	vector<vector<pair<int,int>>> arr(N);
	iota(par.begin(), par.end(), 0);
	for (int i = 0; i < M; i++){
		ed[i]={W[i],{U[i],V[i]}};
		mava=max(mava,W[i]);
	}
	sortarr(ed);
	for (int i = 0; i < M; i++){
		int w = ed[i].first;
		int u = ed[i].second.first;
		int v = ed[i].second.second;
		if (find(u)==find(v)){
			val[u]=min(val[u],w);
			val[v]=min(val[v],w);
			continue;
		}
		arr[u].push_back({v,w});
		arr[v].push_back({u,w});
		merge(u,v);
	}
	for (int i = 0; i < N; i++){
		sort(arr[i].begin(), arr[i].end(), [&](pair<int,int> a, pair<int,int> b){
			return a.second<b.second;
		});
	}
	auto dfs = [&](int node, int lnode, auto dfs)->void{
		int it = 0;
		if (lnode==-1) dep[node]=0;
		else dep[node]=dep[lnode]+1;
		for (int i = 0; i < arr[node].size(); i++){
			if (arr[node][i].first==lnode) continue;
			it++;
			if (it==2){
				c2[node]=arr[node][i].second;
			}
			else if (it==3){
				c3[node]=arr[node][i].second;
			}
			dfs(arr[node][i].first,node,dfs);
			val[node]=min(val[node],max(arr[node][i].second,val[arr[node][i].first]));
			c2[node]=min(c2[node],max(arr[node][i].second,c2[arr[node][i].first]));
			st[arr[node][i].first][0]=node;
			ma[arr[node][i].first][0]=arr[node][i].second;
			mi[node][0]=c2[node];
		}
	};
	auto dfs2 = [&](int node, int lnode, auto dfs2)->void{
		for (int i = 0; i < arr[node].size(); i++){
			if (arr[node][i].first==lnode) continue;
			val[arr[node][i].first]=min(val[arr[node][i].first],max(arr[node][i].second,val[node]));
			dfs2(arr[node][i].first,node,dfs2);
		}
	};
	dfs(0,-1,dfs);
	dfs2(0,-1,dfs2);
	for (int bit = 1; bit < LOG; bit++){
		for (int i = 0; i < N; i ++){
			if (st[i][bit-1]==-1) continue;
			st[i][bit]=st[st[i][bit-1]][bit-1];
			ma[i][bit]=max(ma[i][bit-1],ma[st[i][bit-1]][bit-1]);
			mi[i][bit]=min(mi[i][bit-1],mi[st[i][bit-1]][bit-1]);
		}
	}
}
int32_t getMinimumFuelCapacity(int32_t X, int32_t Y){
	if (lin){
		return -1;
	}
	else {
		return mava;
	}
	pair<pair<int,bool>,pair<int,bool>> pr={{X,true},{Y,true}};
	int ans = 0;
	int ans2 = INF;
	while (pr.first.first!=pr.second.first){
		if (dep[pr.first.first]<dep[pr.second.first]){
			swap(pr.first,pr.second);
		}
		ans2=min(ans2,c2[pr.first.first]);
		ans2=min(ans2,val[pr.first.first]);
		ans=max(ans,ma[pr.first.first][0]);
		pr.first.second=false;
		pr.first.first=st[pr.first.first][0];
	}
	ans2=min(ans2,val[pr.first.first]);
	if (pr.first.second==false && pr.second.second==false){
		ans2=min(ans2,c3[pr.first.first]);
		if (pr.first.first!=0) ans2=min(ans2,ma[pr.first.first][0]);
	}
	ans=max(ans,ans2);
	if (ans==INF) ans=-1;
	return ans;
}

#ifdef tolbi
int32_t main() {
	int32_t N, M;
	assert(2 == scanf("%d %d", &N, &M));

	vector<int32_t> U(M), V(M), W(M);
	for (int32_t i = 0; i < M; ++i) {
		assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
	}

	int32_t Q;
	assert(1 == scanf("%d", &Q));

	vector<int32_t> X(Q), Y(Q);
	for (int32_t i = 0; i < Q; ++i) {
		assert(2 == scanf("%d %d", &X[i], &Y[i]));
	}

	init(N, M, U, V, W);

	vector<int32_t> minimum_fuel_capacities(Q);
	for (int32_t i = 0; i < Q; ++i) {
		minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
		cout<<minimum_fuel_capacities[i]<<endl;
	}

	return 0;
}
#endif

Compilation message

swap.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
swap.cpp: In function 'void init(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:78:21: error: no matching function for call to 'max(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   78 |   mava=max(mava,W[i]);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from swap.cpp:12:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
swap.cpp:78:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   78 |   mava=max(mava,W[i]);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from swap.cpp:12:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
swap.cpp:78:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   78 |   mava=max(mava,W[i]);
      |                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from swap.cpp:12:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
swap.cpp:78:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   78 |   mava=max(mava,W[i]);
      |                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from swap.cpp:12:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
swap.cpp:78:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   78 |   mava=max(mava,W[i]);
      |                     ^
swap.cpp: In instantiation of 'init(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(long long int, long long int, auto:23)> [with auto:23 = init(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(long long int, long long int, auto:23)>]':
swap.cpp:127:14:   required from here
swap.cpp:103:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for (int i = 0; i < arr[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
swap.cpp: In instantiation of 'init(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(long long int, long long int, auto:24)> [with auto:24 = init(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(long long int, long long int, auto:24)>]':
swap.cpp:128:16:   required from here
swap.cpp:121:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |   for (int i = 0; i < arr[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~