답안 #416847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416847 2021-06-03T04:37:58 Z ismoilov Village (BOI20_village) C++14
0 / 100
3 ms 4940 KB
#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
set <int> g[maxx];
bool vis[maxx];
int amn[maxx];
void S()
{
	int n, ans = 0;
	cin >> n;
	fp(i,1,n){
		int x, y;
		cin >> x >> y;
		x --, y --;
		g[x].insert(y);
		g[y].insert(x);
		amn[i] = i;
	}
//	cout << endl;
	fp(x,0,n){
		if(g[x].size() == 1 && vis[x] == 0){
			int y;
			for(int it : g[x])
				y = it;
			g[y].erase(x);
			g[x].erase(y);
			vis[x] = 1, vis[y] = 1;
			swap(amn[x], amn[y]);
			ans += 2;
			//cout << x << " " << y << "first\n";
		}
	}
	
	bool ok = 1;
	while(ok){
		ok = 0;
		fp(x,0,n){
			if(vis[x] == 0){
				set <int> d = g[x];
				for(int y : d){
					if(vis[y] == 1){
						g[x].erase(y);
						g[y].erase(x);
						continue;
					}
					g[y].erase(x);
					g[x].erase(y);
					ans += 2;
					vis[y] = 1, vis[x] = 1;
					swap(amn[x], amn[y]);
					ok = 1;
				//	cout << x << " " << y << "\n";
				}
			}
			/*
			if(g[x].size() == 1){
				int y;
				for(int it : g[x])
					y = it;
				g[y].erase(x);
				g[x].erase(y);
				vis[x] = 1, vis[y] = 1;
				swap(amn[x], amn[y]);
				ok = 1;
				ans += 2;
				cout << x << " ";
			}*/
		}
	}
	cout << ans << "\n";
	fp(i,0,n)
		cout << amn[i]+1 << " ";
	cout << "\n";
	cout << ans << "\n";
	fp(i,0,n)
		cout << i << " ";
}
int main()
{
	IOS;
	S();
}

Compilation message

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:18:2: note: in expansion of macro 'fp'
   18 |  fp(i,1,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:27:2: note: in expansion of macro 'fp'
   27 |  fp(x,0,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:44:3: note: in expansion of macro 'fp'
   44 |   fp(x,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:78:2: note: in expansion of macro 'fp'
   78 |  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:82:2: note: in expansion of macro 'fp'
   82 |  fp(i,0,n)
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Integer parameter [name=vi] equals to 0, violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Integer parameter [name=vi] equals to 294, violates the range [1, 256]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Integer parameter [name=vi] equals to 0, violates the range [1, 4]
2 Halted 0 ms 0 KB -