Submission #802411

#TimeUsernameProblemLanguageResultExecution timeMemory
802411Halym2007Village (BOI20_village)C++11
12 / 100
56 ms468 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define sz size()
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 15;
const int INF = 1e9;
void solve();
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
// indexed_set s;
int cost[N][N], mn, mx, sum;
int n;
int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0), cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	cin >> n;
	vector <int> a(n, 0), jog1(n, 0), jog2(n, 0);
	for (int i = 0; i < n; ++i) {
		a[i] = i;
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			cost[i][j] = INF;
		}
	}
	for (int i = 1; i <= n; ++i) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cost[l][r] = 1;
		cost[r][l] = 1;	
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cost[i][j] = min (cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	mn = INF;
	mx = 0;
	do {
		sum = 0;
		bool tr = 0;
		for (int i = 0; i < n; ++i) {
			if (i == a[i]) tr = 1;
			sum += cost[i][a[i]];
		}
		if (tr) continue;
		if (mn > sum) {
			jog1 = a;
			mn = sum;
		}
		if (mx < sum) {
			jog2 = a;
			mx = sum;
		}
	}while (next_permutation(a.begin(), a.end()));
	cout << mn << ' ' << mx << '\n';
	for (int i : jog1) cout << i + 1 << ' ';
	cout << '\n';
	for (int i : jog2) cout << i + 1 << ' ';
}
/*
                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
             __.'              ~.   .~              `.__
           .'//                  \./                  \`.
         .'//                     |                     \`.
       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \`.
     .'//.-"                 `-.  |  .-'                 "-.\`.
   .'//______.============-..   \ | /   ..-============.______\`.
 .'______________________________\|/______________________________`.
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...