# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
304399 | BeanZ | Spring cleaning (CEOI20_cleaning) | C++14 | 1093 ms | 30660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
vector<ll> adj[N];
vector<ll> node[N];
ll dp[N], sz[N];
void dfs(ll u, ll p){
dp[u] = 0;
sz[u] = 0;
for (auto j : adj[u]){
if (j == p) continue;
dfs(j, u);
dp[u] += dp[j];
sz[u] += sz[j];
dp[u] += sz[j];
}
if (adj[u].size() == 1) sz[u]++;
sz[u] = sz[u] & 1;
if (sz[u] == 0) sz[u] = 2;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, m;
cin >> n >> m;
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
for (int i = 1; i <= m; i++){
ll d;
cin >> d;
for (int j = 1; j <= (n + d); j++){
adj[j] = node[j];
}
for (int j = (n + 1); j <= (n + d); j++){
ll u;
cin >> u;
adj[u].push_back(j);
adj[j].push_back(u);
}
dfs(1, 1);
if (sz[1] == 2) cout << dp[1] << endl;
else cout << -1 << endl;
}
}
/*
7 3
1 2
2 4
4 5
5 6
5 7
3 4
1 4
2 2 4
1 1
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |