Submission #1036557

# Submission time Handle Problem Language Result Execution time Memory
1036557 2024-07-27T13:51:53 Z Alihan_8 Simurgh (IOI17_simurgh) C++17
13 / 100
129 ms 2900 KB
#include "simurgh.h"

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

struct Dsu{
	vector <int> fa;
	
	int n;
	
	Dsu(int n) : n(n){
		fa.resize(n);
		iota(all(fa), 0);
	}
	
	int get(int u){
		return u ^ fa[u] ? fa[u] = get(fa[u]) : u;
	}
	
	bool merge(int u, int v){
		u = get(u), v = get(v);
		
		if ( u == v ){
			return false;
		}
		
		fa[u] = v;
		
		return true;
	}
};

vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	int m = u.size();
	
	vector <int> t(m, -1);
	
	for ( int i = 0; i < m; i++ ){
		Dsu ds(n), tmp(n);
		
		ds.merge(u[i], v[i]);
		
		vector <int> is(m);
		
		is[i] = 1;
		
		vector <int> cur;
		
		for ( int j = 0; j < m; j++ ){
			if ( t[j] == 0 || j == i ) continue;
			
			is[j] = ds.merge(u[j], v[j]);
			
			if ( is[j] > 0 ){
				cur.pb(j);
				
				
				tmp.merge(u[j], v[j]);
			}
		}
		
		cur.pb(i);
		
		if ( cur.size() != n - 1 ){
			t[i] = 0;
			
			continue;
		}
		
		int x = count_common_roads(cur);
		
		if ( x == n - 1 ){
			return cur;
		}
		
		for ( int j = 0; j < m; j++ ){
			if ( is[j] ) continue;
			
			auto q = tmp;
			
			if ( q.merge(u[j], v[j]) ){
				cur.back() = j;
				
				int y = count_common_roads(cur);
				
				if ( x != y ){
					t[i] = (x > y);
					
					break;
				}
			}
		}
	}
	
	vector <int> ret;
	
	for ( int i = 0; i < m; i++ ){
		if ( t[i] > 0 ){
			ret.pb(i);
		}
	}
	
	return ret;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:91:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |   if ( cur.size() != n - 1 ){
      |        ~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 344 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 344 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Incorrect 25 ms 468 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 344 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Incorrect 25 ms 468 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 129 ms 2900 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 344 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 344 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Incorrect 25 ms 468 KB WA in grader: NO
15 Halted 0 ms 0 KB -