Submission #395252

# Submission time Handle Problem Language Result Execution time Memory
395252 2021-04-28T04:10:43 Z suren Swapping Cities (APIO20_swap) C++14
0 / 100
92 ms 95684 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define F first
#define S second
int n, m, flag = true;
vector < int > u, v, w;
vector < int > vc[2000045];
pair < int , pair< int, int > > p[2000045];
int parent[2000045];
int sz[2000045];
int get( ll x ){
	if( parent[x] == x )
		return x;
	parent[x] = get( parent[x] );
}
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
		int i;
		n = N;m = M;u = U;v = V;w = W;
		for( i = 0; i < m; i ++ ){
			p[i].second.F=u[i];
			p[i].second.S=v[i];
			p[i].first=w[i];
		}
		sort( p, p + m );
}
int getMinimumFuelCapacity(int X, int Y) {
	map < int, int > mp;
	int i;
	flag = false;
	mp.clear();
	for( i = 1; i <= n; i ++ ){
			parent[i] = i; 
			sz[i] = 1;
	}
	for( i = 0; i < n; i ++ )
		vc[i].clear();
	for( i = 0; i < m; i ++ ){
		int x = get( p[i].second.F );
		int y = get( p[i].second.S );
		if( x != y ){
			if( y > x ){
				swap(y, x);
			} 
			parent[y] = x;
			sz[x] += sz[y]; 
		}
		int parx = get( X );
		int pary = get( Y );
		vc[ p[i].second.F ].pb( p[i].second.S );
		vc[ p[i].second.S ].pb( p[i].second.F );
		mp[p[i].second.F] = 1;
		mp[ p[i].second.S ] = 1;
		for(;;);
		if( vc[ p[i].S.F ].size() == 3 ){
			if( parent[p[i].S.F] == parx || parent[p[i].S.F] == pary )
				flag = true;
		}
		if( vc[ p[i].S.S ].size() == 3 ){
			if( parent[p[i].S.S] == parx || parent[p[i].S.S] == pary )
				flag = true;
		}
		if( mp.size() == i+1 && mp[Y] == 1 && mp[X] == 1 && parx == pary ){
			return p[i].first;
		}
		if( mp[Y] == 1 && mp[X] == 1 && flag == true && parx == pary )
			return p[i].first;
	}
	return -1;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:66:17: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |   if( mp.size() == i+1 && mp[Y] == 1 && mp[X] == 1 && parx == pary ){
      |       ~~~~~~~~~~^~~~~~
swap.cpp: In function 'int get(long long int)':
swap.cpp:17:12: warning: control reaches end of non-void function [-Wreturn-type]
   17 |  parent[x] = get( parent[x] );
      |  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 95684 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -