Submission #1048607

# Submission time Handle Problem Language Result Execution time Memory
1048607 2024-08-08T08:40:15 Z LittleOrange Simurgh (IOI17_simurgh) C++17
13 / 100
53 ms 440 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
	ll n;
	vector<ll> p;
	dsu(ll N):n(N),p(N,-1){}
	ll g(ll i){
		return p[i]<0?i:p[i] = g(p[i]);
	}
	bool m(ll a, ll b){
		a = g(a);
		b = g(b);
		if(a==b) return false;
		if (p[a]>p[b]) swap(a,b);
		p[a] += p[b];
		p[b] = a;
		return true;
	}
};
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	mt19937_64 mt(random_device{}());
	ll m = u.size();
	if (m<=28){
		for(ll j = 0;j<(1<<m);j++) if(__builtin_popcount(j)==n-1){
			vector<ll> r;
			for(ll i = 0;i<m;i++) if(j>>i&1) r.push_back(i);
			dsu d(n);
			ll ok = 1;
			for(ll i : r){
				if(!d.m(u[i],v[i]))ok = 0;
			}
			if(ok){
				ll g = count_common_roads(r);
				if (g==n-1){
					return r;
				}
			}
		}
	}
	vector<ll> ls(m);
	iota(ls.begin(),ls.end(),0);
	shuffle(ls.begin(),ls.end(),mt);
	vector<ll> a;
	{
		dsu d(n);
		for(ll i = 0;a.size()<n-1;i++) if(d.m(u[i],v[i]))a.push_back(i);
	}
	ll sc = count_common_roads(a);
	while(sc<n-1){
		shuffle(a.begin(),a.end(),mt);
		vector<ll> b;
		for(ll i = 0;i<sc;i++) b.push_back(a[i]);
		dsu d(n);
		for(ll i : b) d.m(u[i],v[i]);
		for(ll i = 0;b.size()<n-1;i++) if(d.m(u[i],v[i]))b.push_back(i);
		ll nsc = count_common_roads(b);
		if (nsc>sc){
			sc = nsc;
			a = b;
		}
	}
	return a;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:48:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   for(ll i = 0;a.size()<n-1;i++) if(d.m(u[i],v[i]))a.push_back(i);
      |                ~~~~~~~~^~~~
simurgh.cpp:57:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   for(ll i = 0;b.size()<n-1;i++) if(d.m(u[i],v[i]))b.push_back(i);
      |                ~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 432 KB correct
2 Correct 12 ms 344 KB correct
3 Correct 14 ms 440 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 2 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 6 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 432 KB correct
2 Correct 12 ms 344 KB correct
3 Correct 14 ms 440 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 2 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 6 ms 348 KB correct
14 Incorrect 53 ms 348 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 432 KB correct
2 Correct 12 ms 344 KB correct
3 Correct 14 ms 440 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 2 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 6 ms 348 KB correct
14 Incorrect 53 ms 348 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 Incorrect 6 ms 436 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 432 KB correct
2 Correct 12 ms 344 KB correct
3 Correct 14 ms 440 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 2 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 6 ms 348 KB correct
14 Incorrect 53 ms 348 KB WA in grader: NO
15 Halted 0 ms 0 KB -