이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef __APPLE__
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <immintrin.h>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#if __APPLE__
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct stsum_add {
static const int Nst = 1e5 + 42;
ll st[Nst * 4];
ll lazy[Nst * 4];
int tree_l[Nst * 4], tree_r[Nst * 4];
ll seg_len[Nst * 4];
void push(int v) {
if (!lazy[v]) return;
st[(v << 1)] += lazy[v] * seg_len[(v << 1)];
st[(v << 1) + 1] += lazy[v] * seg_len[(v << 1) + 1];
lazy[(v << 1)] += lazy[v];
lazy[(v << 1) + 1] += lazy[v];
lazy[v] = 0;
}
void init(int v = 1, int tl = 0, int tr = Nst - 1) {
tree_l[v] = tl;
tree_r[v] = tr;
seg_len[v] = (tr - tl + 1);
if (tl == tr) {
st[v] = 0;
lazy[v] = 0;
}
else {
int tm = (tl + tr) / 2;
init((v << 1), tl, tm);
init((v << 1) + 1, tm + 1, tr);
st[v] = 0;
lazy[v] = 0;
}
}
ll get(int l, int r, int v = 1, int tl = 0, int tr = Nst - 1) {
if (l > r) return 0;
if (l <= tl && tr <= r) return st[v];
push(v);
int tm = ((tl + tr) >> 1);
return (get(l, min(r, tm), (v << 1), tl, tm) + get(max(l, tm + 1), r, (v << 1) + 1, tm + 1, tr));
}
void upd(int l, int r, ll delta, int v = 1, int tl = 0, int tr = Nst - 1) {
if (l > r) return;
if (l == tl && r == tr) {
st[v] += delta * seg_len[v];
lazy[v] += delta;
} else {
push(v);
int tm = ((tl + tr) >> 1);
upd(l, min(r, tm), delta, (v << 1), tl, tm);
upd(max(l, tm + 1), r, delta, (v << 1) + 1, tm + 1, tr);
st[v] = (st[(v << 1)] + st[(v << 1) + 1]);
}
}
};
stsum_add st;
struct HLD {
static const int maxN = 1e5 + 42;
vector<int> g[maxN];
int head[maxN] = {}, parent[maxN] = {}, depth[maxN] = {}, subt[maxN] = {};
int pos[maxN] = {};
int curpos = 0;
bool VALS_IN_EDGES = 0;
void init(int root) {
parent[root] = depth[root] = curpos = 0;
predfs(root);
head[root] = root;
dfsHLD(root);
}
void add_edge(int a, int b) {
g[a].pb(b);
g[b].pb(a);
}
void predfs(int v) {
subt[v] = 1;
for (auto &to: g[v]) {
parent[to] = v;
depth[to] = depth[v] + 1;
g[to].erase(find(all(g[to]), v));
predfs(to);
subt[v] += subt[to];
if (subt[to] > subt[g[v][0]]) swap(g[v][0], to);
}
}
void dfsHLD(int v) {
pos[v] = curpos++;
for (auto &to: g[v]) {
head[to] = (to == g[v][0] ? head[v] : to);
dfsHLD(to);
}
}
int lca(int a, int b) {
for (; head[a] != head[b]; b = parent[head[b]]) {
if (depth[head[a]] > depth[head[b]]) swap(a, b);
}
if (depth[a] > depth[b]) swap(a, b);
return a;
}
int query_path(int a, int b) {
int res = 0;
for (; head[a] != head[b]; b = parent[head[b]]) {
if (depth[head[a]] > depth[head[b]]) swap(a, b);
res += st.get(pos[head[b]], pos[b]);
}
if (depth[a] > depth[b]) swap(a, b);
res += st.get(pos[a] + VALS_IN_EDGES, pos[b]);
return res;
}
void upd_path(int a, int b, int val) {
for (; head[a] != head[b]; b = parent[head[b]]) {
if (depth[head[a]] > depth[head[b]]) swap(a, b);
st.upd(pos[head[b]], pos[b], val);
}
if (depth[a] > depth[b]) swap(a, b);
st.upd(pos[a] + VALS_IN_EDGES, pos[b], val);
}
void upd_subtree(int v, int val) {
st.upd(pos[v] + VALS_IN_EDGES, pos[v] + subt[v] - 1, val);
}
};
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<pair<int, int> > edg(n - 1);
HLD hld; hld.VALS_IN_EDGES = true; st.init();
for(int i = 0; i + 1 < n; i++) {
cin >> edg[i].fi >> edg[i].se;
edg[i].fi--; edg[i].se--;
hld.add_edge(edg[i].fi, edg[i].se);
}
hld.init(0);
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b; a--; b--;
hld.upd_path(a, b, 1);
}
vector<int> ans;
for(int i = 0; i + 1 < n; i++) {
if(hld.query_path(edg[i].fi, edg[i].se) >= k) ans.pb(i + 1);
}
cout << len(ans) << '\n';
for(auto& x : ans) cout << x << ' ';
}
signed main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
}
/*
KIVI
*/
# | 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... |