이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int MaxN = 2e5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
struct LCA{
vi st, ed, _lg, high, par, ans, a, b, labp;
vector <vi> euler, adj;
int cnt;
void dfs(int u, int pa){
++ cnt;
st[u] = cnt;
euler[cnt].pb(u);
for (int id : adj[u]){
int v = a[id] ^ b[id] ^ u;
if (v == pa) {
labp[u] = id;
continue;
}
high[v] = high[u] + 1;
dfs(v, u);
euler[++ cnt].pb(u);
}
ed[u] = cnt;
}
int check(int u, int v) {
return st[u] <= st[v] && ed[v] <= ed[u];
}
int min_by_time(int u, int v) {
return (st[u] < st[v] ? u : v);
}
void add(int u, int v){
a.pb(u);
b.pb(v);
adj[u].pb(a.size() - 1);
adj[v].pb(a.size() - 1);
}
LCA(int n){
st.resize(n + 3, 0);
par.resize(n + 3, 0);
labp.resize(n + 3, 0);
ans.resize(n + 3, 0);
ed.resize(n + 3, 0);
euler.resize(2 * n + 5);
adj.resize(n + 3);
_lg.resize(2 * n + 5);
high.resize(n + 3, 1);
for (int i = 0; i <= 2 * n; ++ i) _lg[i] = log2(i);
}
int get(int u, int v) {
int L = min(st[u], st[v]);
int R = max(ed[u], ed[v]);
int lg = _lg[R - L + 1];
return min_by_time(euler[L][lg], euler[R - (1 << lg) + 1][lg]);
}
void init(int r){
cnt = 0;
dfs(r, 0);
for (int lg = 1; lg < 20; ++lg) {
for (int i = 1; i + (1 << lg) - 1 <= cnt; ++i)
euler[i].pb(min_by_time(euler[i][lg - 1], euler[i + (1 << lg - 1)][lg - 1]));
}
}
int dist(int u, int v){
int lc = get(u, v);
return high[u] + high[v] - 2 * high[lc];
}
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin())
#define uq(sr) (sr).erase(unique(all((sr))), (sr).end())
void process(vector <int> s){
int n = s.size();
sort(all(s), [&](int u, int v){
return st[u] < st[v];
});
for (int i = 1; i < n; ++ i) s.pb(get(s[i], s[i - 1]));
sort(all(s), [&](int u, int v){
return st[u] < st[v];
});
uq(s); vi st;
reverse(all(s));
for (int u : s){
while (st.size() && check(u, st.back())){
par[st.back()] = u;
ans[st.back()] ++;
ans[u] --;
st.pop_back();
}
st.push_back(u);
}
}
void last(int u, int pa){
for (int id : adj[u]){
int v = a[id] ^ b[id] ^ u;
if (v ^ pa) {
last(v, u);
ans[u] += ans[v];
}
}
}
};
void solve(){
int n, m, k; cin >> n >> m >> k;
LCA tree(n);
for (int i = 1, a, b; i < n; ++ i) cin >> a >> b, tree.add(a, b);
tree.init(1);
while (m --) {
int t; cin >> t;
vi s; while (t --){
int a; cin >> a; s.pb(a);
}
tree.process(s);
}
tree.last(1, 0); int ans = 0; vi used(n - 1, 0);
for (int i = 1; i <= n; ++ i) if (tree.ans[i] >= k) {++ ans; used[tree.labp[i]] = 1;}
cout << ans << '\n';
for (int i = 0; i < n - 1; ++ i) if (used[i]) {
-- ans;
cout << i + 1;
if (ans) cout << ' ';
}
}
int main(){
if (fopen("railway.inp", "r")){
freopen("railway.inp", "r", stdin);
freopen("railway.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
railway.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
railway.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
railway.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
railway.cpp: In member function 'void LCA::init(int)':
railway.cpp:83:78: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
83 | euler[i].pb(min_by_time(euler[i][lg - 1], euler[i + (1 << lg - 1)][lg - 1]));
| ~~~^~~
railway.cpp: In function 'int main()':
railway.cpp:154:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
154 | freopen("railway.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:155:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
155 | freopen("railway.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |