# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
676384 | flashhh | Railway (BOI17_railway) | C++17 | 201 ms | 42196 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(numPlans);
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);
sort(acceptedEdges.begin(), acceptedEdges.end());
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;
}
컴파일 시 표준 에러 (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... |