Submission #743998

# Submission time Handle Problem Language Result Execution time Memory
743998 2023-05-18T07:06:08 Z tolbi Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 29972 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<pair<int,int>>> arr;
#include "swap.h"
void init(int32_t N, int32_t M, vector<int32_t> U, vector<int32_t> V, vector<int32_t> W) {
	arr.resize(N);
	for (int i = 0; i < M; i++){
		arr[U[i]].push_back({V[i],W[i]});
		arr[V[i]].push_back({U[i],W[i]});
	}
}
int32_t getMinimumFuelCapacity(int32_t X, int32_t Y){
	vector<bool> vis(arr.size(),false);
	bool don = false;
	priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;
	pq.push({0,{X,-1}});
	map<pair<int,int>,bool> kul;
	vector<int> dal(arr.size());
	int ans = 0;
	bool boolean=false;
	while (pq.size()){
		int tim = pq.top().first;
		int gel = pq.top().second.second;
		int node = pq.top().second.first;
		pq.pop();
		ans=max(ans,tim);
		if (gel!=-1) kul[{gel,node}]=true;
		if (vis[node]){
			don=true;
			if (vis[Y] && don) {
				boolean=true;
				break;
			}
			continue;
		}
		vis[node]=true;
		if (gel!=-1) dal[gel]++;
		if (gel!=-1 && gel!=X && gel!=Y && dal[gel]>=2){
			don=true;
		}
		if (vis[Y] && don){
			boolean=true;
			break;
		}
		for (int i = 0; i < arr[node].size(); i++){
			if (kul.count({arr[node][i].first,node})) continue;
			pq.push({arr[node][i].second,{arr[node][i].first,node}});
		}
	}
	if (!boolean) 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 'int32_t getMinimumFuelCapacity(int32_t, int32_t)':
swap.cpp:82: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]
   82 |   for (int i = 0; i < arr[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Correct 3 ms 440 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 172 ms 14264 KB Output is correct
10 Correct 385 ms 17124 KB Output is correct
11 Correct 469 ms 16768 KB Output is correct
12 Correct 519 ms 17848 KB Output is correct
13 Correct 463 ms 17724 KB Output is correct
14 Execution timed out 2051 ms 14452 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Execution timed out 2068 ms 22464 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Correct 3 ms 440 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 612 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 4 ms 596 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 440 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 172 ms 14264 KB Output is correct
11 Correct 385 ms 17124 KB Output is correct
12 Correct 469 ms 16768 KB Output is correct
13 Correct 519 ms 17848 KB Output is correct
14 Correct 463 ms 17724 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 444 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 2 ms 452 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 612 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 16 ms 2516 KB Output is correct
35 Correct 349 ms 16932 KB Output is correct
36 Correct 225 ms 16080 KB Output is correct
37 Correct 348 ms 17204 KB Output is correct
38 Correct 458 ms 17416 KB Output is correct
39 Correct 231 ms 16548 KB Output is correct
40 Correct 291 ms 15984 KB Output is correct
41 Correct 280 ms 18008 KB Output is correct
42 Correct 268 ms 16652 KB Output is correct
43 Correct 223 ms 16800 KB Output is correct
44 Correct 262 ms 17668 KB Output is correct
45 Correct 500 ms 23328 KB Output is correct
46 Correct 427 ms 17716 KB Output is correct
47 Correct 336 ms 17636 KB Output is correct
48 Correct 485 ms 19872 KB Output is correct
49 Correct 155 ms 25624 KB Output is correct
50 Correct 162 ms 19964 KB Output is correct
51 Correct 287 ms 22468 KB Output is correct
52 Correct 246 ms 25100 KB Output is correct
53 Correct 349 ms 28788 KB Output is correct
54 Correct 536 ms 29972 KB Output is correct
55 Correct 308 ms 17552 KB Output is correct
56 Correct 763 ms 28816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Correct 3 ms 440 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 172 ms 14264 KB Output is correct
10 Correct 385 ms 17124 KB Output is correct
11 Correct 469 ms 16768 KB Output is correct
12 Correct 519 ms 17848 KB Output is correct
13 Correct 463 ms 17724 KB Output is correct
14 Execution timed out 2051 ms 14452 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 440 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 172 ms 14264 KB Output is correct
11 Correct 385 ms 17124 KB Output is correct
12 Correct 469 ms 16768 KB Output is correct
13 Correct 519 ms 17848 KB Output is correct
14 Correct 463 ms 17724 KB Output is correct
15 Execution timed out 2051 ms 14452 KB Time limit exceeded
16 Halted 0 ms 0 KB -