This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismi ALlah
#include "bits/stdc++.h"
using namespace std;
vector <vector <int>> g;
int f;
multiset <pair <int,int>> path;
void dfs(int v, const int & target, int p = -1) {
if(p != -1) path.insert({min(v, p), max(v, p)});
if(v == target) {
f = 1;
return;
}
for(auto u : g[v]) {
if(u == p) continue;
dfs(u, target, v);
if(f) return;
}
path.erase(path.find({min(v, p), max(v, p)}));
}
signed main () {
int n, m, k;
cin >> n >> m >> k;
g.resize(n);
map <pair <int,int>,int> edge;
vector <int> cnt(n-1, 0);
for(int i = 0; i < n - 1; i ++) {
int u, v;
cin >> u >> v;
u --, v --;
edge[{min(u, v), max(u, v)}] = i;
g[v].push_back(u);
g[u].push_back(v);
}
for(;m>=1;m--) {
int sz;
cin >> sz;
vector <int> need;
for(int v;sz>=1;sz--) {
cin >> v;
v --;
need.push_back(v);
}
int prev = need[0];
for(int i = 1; i < need.size(); i ++) {
f = 0;
dfs(need[i], prev);
}
set <pair <int,int>> forPath;
for(auto i : path) forPath.insert(i);
for(auto i : forPath) {
// cout << i.first + 1 << " " << i.second + 1 << "\n";
cnt[edge[i]] ++;
}
//cout << "\n";
path.clear();
}
vector <int> ans;
for(int i= 0; i < cnt.size(); i ++) {
if(cnt[i] >= k) ans.push_back(i + 1);
}
cout << ans.size() << "\n";
for(auto i : ans) cout << i << " ";
return 0;
}
Compilation message (stderr)
railway.cpp: In function 'int main()':
railway.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 1; i < need.size(); i ++) {
| ~~^~~~~~~~~~~~~
railway.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i= 0; i < cnt.size(); i ++) {
| ~~^~~~~~~~~~~~
# | 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... |