This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 1e5+5;
vl g[sz];
set<ll>st[sz], stt[2];
ll vis[sz];
void dfs(ll f, ll node, ll h)
{
vis[node] = 1;
for(auto h : st[node])
stt[f].insert(h);
for(auto u : g[node])
{
if(vis[u] || u == h)
continue;
dfs(f, u, h);
}
}
void solve()
{
ll n, m, k, i, j;
cin >> n >> m >> k;
vector<pll>vect;
for(i = 1; i <= n - 1; i++)
{
ll x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
vect.pb({x, y});
}
for(i = 1; i <= m; i++)
{
ll s;
cin >> s;
for(j = 1; j <= s; j++)
{
ll x;
cin >> x;
st[x].insert(i);
}
}
vl f;
for(i = 0; i < vect.size(); i++)
{
for(j = 1; j <= n; j++)
vis[j] = 0;
stt[0].clear();
stt[1].clear();
ll x = vect[i].f, y = vect[i].s;
dfs(0, x, y);
dfs(1, y, x);
set<ll> st1 = stt[0], st2 = stt[1];
ll sm = 0;
for(auto u : st2)
{
ll sz = st1.size();
st1.insert(u);
if(sz == st1.size())
sm++;
}
if(sm >= k)
f.pb(i+1);
}
cout << f.size() << "\n";
for(auto u : f)
cout << u << ' ';
cout << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
solve();
}
}
Compilation message (stderr)
railway.cpp: In function 'void solve()':
railway.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(i = 0; i < vect.size(); i++)
| ~~^~~~~~~~~~~~~
railway.cpp:76:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::set<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if(sz == st1.size())
| ~~~^~~~~~~~~~~~~
# | 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... |