Submission #416851

#TimeUsernameProblemLanguageResultExecution timeMemory
416851ismoilovVillage (BOI20_village)C++14
12 / 100
54 ms320 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define maxx 100010
int a[11][11];
void S()
{
	int n, ans = 0;
	cin >> n;
	if(n > 10){
		return;
	}
	fp(i,0,n){
		fp(j,0,n)
			a[i][j] = maxx;
		a[i][i] = 0;
	}
	fp(i,1,n){
		int x, y;
		cin >> x >> y;
		x --, y --;
		a[x][y] = 1;
		a[y][x] = 1;
	}
	fp(k,0,n){
		fp(i,0,n){
			fp(j,0,n){
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
	vector <int> b, mn_ar, mx_ar;
	fp(i,0,n)
		b.push_back(i);
	int mn = maxx, mx = -maxx;
	do{
		int s = 0;
		bool ok = 1;
		fp(i,0,n){
			if(b[i] == i){
				ok = 0;
				break;
			}
			s += a[i][b[i]];
		}
		if(!ok)
			continue;
		if(s < mn){
			mn = s;
			mn_ar = b;
		}
		if(s > mx){
			mx = s;
			mx_ar = b;
		}
	}while(next_permutation(all(b)));
	cout << mn << " " << mx << "\n";
	fp(i,0,n)
		cout << mn_ar[i] + 1 << " ";
	cout << endl;
	fp(i,0,n)
		cout << mx_ar[i] +1 << " ";
}
int main()
{
	IOS;
	S();
}

Compilation message (stderr)

Village.cpp: In function 'void S()':
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:19:2: note: in expansion of macro 'fp'
   19 |  fp(i,0,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:20:3: note: in expansion of macro 'fp'
   20 |   fp(j,0,n)
      |   ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:24:2: note: in expansion of macro 'fp'
   24 |  fp(i,1,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:31:2: note: in expansion of macro 'fp'
   31 |  fp(k,0,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:32:3: note: in expansion of macro 'fp'
   32 |   fp(i,0,n){
      |   ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:33:4: note: in expansion of macro 'fp'
   33 |    fp(j,0,n){
      |    ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:39:2: note: in expansion of macro 'fp'
   39 |  fp(i,0,n)
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:45:3: note: in expansion of macro 'fp'
   45 |   fp(i,0,n){
      |   ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:64:2: note: in expansion of macro 'fp'
   64 |  fp(i,0,n)
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:67:2: note: in expansion of macro 'fp'
   67 |  fp(i,0,n)
      |  ^~
Village.cpp:14:9: warning: unused variable 'ans' [-Wunused-variable]
   14 |  int n, ans = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...