Submission #676380

#TimeUsernameProblemLanguageResultExecution timeMemory
676380flashhhRailway (BOI17_railway)C++14
0 / 100
121 ms40832 KiB
#include <bits/stdc++.h> using namespace std; int numVertices, numPlans, minimumPlans; vector<int> acceptedEdges; vector<int> numVerticesOnPlan; vector<vector<int> > plansOfVertice; vector<vector<pair<int,int> > > adj; void Read() { cin >> numVertices >> numPlans >> minimumPlans; numVerticesOnPlan.resize(numVertices); adj.resize(numVertices); plansOfVertice.resize(numVertices); for (int numEdge = 0; numEdge < numVertices - 1; ++numEdge) { int u,v; cin >> u >> v; --u; --v; adj[u].emplace_back(numEdge, v); adj[v].emplace_back(numEdge, u); } for (int numPlan = 0; numPlan < numPlans; ++numPlan) { int planQuantity; cin >> planQuantity; numVerticesOnPlan[numPlan] = planQuantity; while (planQuantity--) { int vertice; cin >> vertice; --vertice; plansOfVertice[vertice].push_back(numPlan); } } } void calculate() { vector<map<int,int> > myMap; myMap.resize(numVertices); auto dfs = [&] (int u, int cha, int prevEdge, auto&& dfs) -> void { for (int plan : plansOfVertice[u]) ++myMap[u][plan]; for (auto [numEdge, v] : adj[u]) { if (v == cha) continue; dfs(v, u, numEdge, dfs); if (myMap[u].size() < myMap[v].size()) swap(myMap[u], myMap[v]); for (map<int,int> :: iterator it = myMap[v].begin(); it != myMap[v].end(); ++it) { int plan = it -> first; int quantity = it -> second; myMap[u][plan] += quantity; if (myMap[u][plan] == numVerticesOnPlan[plan]) myMap[u].erase(plan); } } if (myMap[u].size() >= minimumPlans) acceptedEdges.push_back(prevEdge); }; dfs(0, -1, -1, dfs); cout << acceptedEdges.size() <<'\n'; for (auto numEdge : acceptedEdges) cout << numEdge + 1 <<" "; cout <<'\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Read(); calculate(); return 0; }

Compilation message (stderr)

railway.cpp: In lambda function:
railway.cpp:48:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         for (auto [numEdge, v] : adj[u]) {
      |                   ^
railway.cpp: In function 'void calculate()':
railway.cpp:68:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   68 |     for (auto numEdge : acceptedEdges) cout << numEdge + 1 <<" "; cout <<'\n';
      |     ^~~
railway.cpp:68:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   68 |     for (auto numEdge : acceptedEdges) cout << numEdge + 1 <<" "; cout <<'\n';
      |                                                                   ^~~~
railway.cpp: In instantiation of 'calculate()::<lambda(int, int, int, auto:1&&)> [with auto:1 = calculate()::<lambda(int, int, int, auto:1&&)>&]':
railway.cpp:65:23:   required from here
railway.cpp:62:29: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |         if (myMap[u].size() >= minimumPlans) acceptedEdges.push_back(prevEdge);
      |             ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
#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...