답안 #390424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390424 2021-04-16T04:12:53 Z talant117408 Spring cleaning (CEOI20_cleaning) C++17
0 / 100
40 ms 5764 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 1e9+7;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

const int N = 1e5+7;
vector <int> graph[N];
int n;

bool subtask1() {
	return sz(graph[1]) == n-1;
}

bool subtask2() {
	bool flag = 1;
	for (int i = 1; i <= n; i++) {
		if (i == 1) {
			if (sz(graph[1]) != 1 || graph[1][0] != 2) flag = 0;
		}
		else if (i == n) {
			if (sz(graph[n]) != 1 || graph[n][0] != n-1) flag = 0;
		}
		else if (sz(graph[i]) != 2 || min(graph[i][0], graph[i][1]) != i-1 || max(graph[i][0], graph[i][1]) != i+1) {
			flag = 0;
		}
	}
	return flag;
}

int main() {
	do_not_disturb
	
	int q;
	cin >> n >> q;
	for (int i = 0; i < n-1; i++) {
		int x, y;
		cin >> x >> y;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	
	if (subtask1()) {
		while (q--) {
			int m;
			cin >> m;
			vector <int> d(m);
			for (auto &to : d) cin >> to;
			if (n&1) {
				cout << n+m << endl;
			}
			else {
				cout << -1 << endl;
			}
		}
	}
	else if (subtask2()) {
		while (q--) {
			int m;
			cin >> m;
			vector <int> d(m);
			for (auto &to : d) cin >> to;
			sort(all(d));
			if (sz(d)&1) {
				cout << -1 << endl;
			}
			else {
				ll ans = n;
				for (int i = 0; i < sz(d); i += 2) {
					ans += abs(d[i]-d[i-1])+2;
				}
				cout << ans << endl;
			}
		}
	}
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 3148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 3276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 4676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 5764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -