Submission #304399

#TimeUsernameProblemLanguageResultExecution timeMemory
304399BeanZSpring cleaning (CEOI20_cleaning)C++14
34 / 100
1093 ms30660 KiB
// 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 */

Compilation message (stderr)

cleaning.cpp: In function 'int main()':
cleaning.cpp:30:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   30 |                 freopen("test.inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cleaning.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   31 |                 freopen("test.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...