이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pi pair<int,int>
#define pb push_back
#define V vector
#define vi V<int>
#define mi map<int,int>
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define ins insert
#define qi queue<int>
#define pqi priority_queue<int>
#define si set<int>
#define v2i V<vi>
#define v3i V<v2i>
#define v4i V<v3i>
#define v5i V<v4i>
#define INF 1e18
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define print(x) cout << x<<" ";
#define vpi V<pi>
#define Y cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define msi multiset<int>
#define F first
#define S second
#define ld long double
#define RE return;
#define IMP cout<<-1<<endl;return;
using namespace std;
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T>& vec) {
for (T& x : vec) {
in >> x;
}
return in;
}
v2i adj;
map<pi,int> edge;
v2i bin;
const int mx = 17;
vi cnt;
vi order; int k;
vi depth;
int zawg=0;
void dfs(int node, int x){
bin[node][0] = x;
order[node] = zawg++;
for(int i=1; i<mx; i++) bin[node][i] = bin[bin[node][i-1]][i-1];
for(auto &y: adj[node])if(y!=x){
depth[y] = depth[node]+1;
dfs(y, node);
cnt[node] += cnt[y];
}
}
int kth(int x, int k){
for(int i=0; i<mx; i++)if((1<<i)&k) x = bin[x][i];
return x;
}
int lca(int x, int y){
if(depth[x]>depth[y]) swap(x,y);
y = kth(y, depth[y]-depth[x]);
if(x==y) return x;
for(int i=mx-1; i>=0; i--){
if(bin[x][i] != bin[y][i]) x = bin[x][i], y = bin[y][i];
}
return bin[x][0];
}
bool ord(int a, int b){return order[a]<order[b];}
signed main(){
int n,m;cin>>n>>m>>k; bin= v2i(n, vi(17)); adj.resize(n); cnt.resize(n); order.resize(n); depth.resize(n);
for(int i=1; i<n; i++){
int x,y; cin>>x>>y; x--;y--;
edge[{x,y}]=i; edge[{y,x}]=i;
adj[x].pb(y); adj[y].pb(x);
}
dfs(0,0);
for(int i=0; i<m; i++){
int s; cin >> s;
vi jhxt(s); cin >>jhxt; for(auto &j: jhxt) j--;
sort(all(jhxt), ord);
jhxt.pb(jhxt[0]);
for(int j=0; j<s; j++){
int lc = lca(jhxt[j], jhxt[j+1]);
cnt[lc]-=2; cnt[jhxt[j]]++; cnt[jhxt[j+1]]++;
}
}
dfs(0,0);
si ans;
for(int i=1; i<n; i++)if(cnt[i]>=2*k) ans.ins(edge[{i,bin[i][0]}]);
cout<<sz(ans)<<endl;
for(auto &x: ans) cout<<x<<" ";
}
# | 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... |