This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
VVPI gp;
VI val;
void increment(int u, int v) {
val[u]--;
val[v]++;
}
void getall(int u = 0, int p = -1) {
for (auto[v, i] : gp[u]) if (v != p) {
getall(v, u);
val[u] += val[v];
}
}
VI tin, tout;
VI paredge;
int tc = 0;
VVI par;
void dfs(int u = 0, int p = 0, int pi = -1) {
tin[u] = tc++;
paredge[u] = pi;
par[u][0] = p;
replr(i, 1, 19) par[u][i] = par[par[u][i-1]][i-1];
for (auto[v, i] : gp[u]) if (v != p) {
dfs(v, u, i);
}
tout[u] = tc++;
}
bool isanc(int u, int v) {
return tin[u] <= tin[v] && tout[v] <= tout[u];
}
int LCA(int u, int v) {
if (isanc(u, v)) return u;
reprl(i, 19, 0) if (!isanc(par[u][i], v)) u = par[u][i];
return par[u][0];
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
gp = VVPI(n);
rep(i, n-1) {
int u, v;
cin >> u >> v;
u--, v--;
gp[u].pb({v, i});
gp[v].pb({u, i});
}
tin = tout = VI(n);
par = VVI(n, VI(20));
paredge = VI(n);
tc = 1;
dfs();
val = VI(n);
rep(i, m) {
int s;
cin >> s;
VPI a(s);
for (auto&[t, u] : a) {
cin >> u;
u--;
t = tin[u];
}
sort(all(a));
rep(i, s) {
int j = (i+1)%a.size();
int lca = LCA(a[i].ss, a[j].ss);
increment(lca, a[i].ss);
increment(lca, a[j].ss);
}
}
getall();
VI ans;
rep(u, n) if (val[u] >= 2*k) ans.pb(paredge[u]+1);
sort(all(ans));
cout << ans.size() << endl;
for (int x : ans) cout << x << " "; cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
/* cin >> t; */
while (t--) solve();
}
Compilation message (stderr)
railway.cpp: In function 'void getall(int, int)':
railway.cpp:41:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
41 | for (auto[v, i] : gp[u]) if (v != p) {
| ^
railway.cpp: In function 'void dfs(int, int, int)':
railway.cpp:56:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for (auto[v, i] : gp[u]) if (v != p) {
| ^
railway.cpp: In function 'void solve()':
railway.cpp:92:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
92 | for (auto&[t, u] : a) {
| ^
railway.cpp:110:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
110 | for (int x : ans) cout << x << " "; cout << endl;
| ^~~
railway.cpp:110:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
110 | for (int x : ans) cout << x << " "; cout << endl;
| ^~~~
# | 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... |