Submission #795969

#TimeUsernameProblemLanguageResultExecution timeMemory
795969NeroZeinSpring cleaning (CEOI20_cleaning)C++17
0 / 100
48 ms6692 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif const int N = 100005; vector<int> g[N]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } while (q--) { int d; cin >> d; vector<int> nodes(d); for (int i = 0; i < d; ++i) { cin >> nodes[i]; } if (d % 2) { cout << -1 << '\n'; } int ans = n - 1 + d; sort(nodes.begin(), nodes.end()); for (int i = 0; i < d; i += 2) { ans += nodes[i + 1] - nodes[i]; } cout << ans << '\n'; } return 0; }
#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...