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 optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//ahmet23 orz...
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& is, pair<X,Y> &pr){return is>>pr.first>>pr.second;}
#ifdef tolbi
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<"{ "<<pr.first<<", "<<pr.second<<" }";}
#else
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<pr.first<<" "<<pr.second;}
#endif
ostream& operator<<(ostream& os, bool bl){return os<<(int32_t)bl;}
template<typename X> istream& operator>>(istream& is, vector<X> &arr){for (auto &it : arr) is>>it; return is;}
template<typename X, size_t Y> istream& operator>>(istream& is, array<X,Y> &arr){for (auto &it : arr) is>>it; return is;}
template<typename X> ostream& operator<<(ostream& os, vector<X> &arr){for (auto &it : arr) os<<" "<<it;os<<endl;return os;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> &arr){for (auto &it : arr) os<<" "<<it;os<<endl;return os;}
#define int long long
#define endl '\n'
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for(auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define rev(x) reverse(x.begin(), x.end())
#define tol(bi) (1LL<<((int)(bi)))
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = LONG_LONG_MAX;
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
int32_t main(){
ios;
int T = 1;
if (!T) cin>>T;
int tno = 0;
while (T-(tno++)){
deci(n);deci(m);deci(k);
vector<map<int,int>> mp(n);
vector<int> sz(m);
vector<vector<int>> arr(n);
vector<vector<int>> ed(n);
for (int i = 0; i < n-1; ++i)
{
deci(u);deci(v);
arr[u-1].push_back(v-1);
arr[v-1].push_back(u-1);
ed[u-1].push_back(i+1);
ed[v-1].push_back(i+1);
}
for (int i = 0; i < m; ++i)
{
cin>>sz[i];
for (int j = 0; j < sz[i]; ++j)
{
deci(x);
mp[x-1][i]=1;
}
}
vector<int> pared(n);
vector<int> ansarr;
auto f = [&](int node, int lnode, auto f)->void{
for (int i = 0; i < arr[node].size(); i++){
if (arr[node][i]==lnode) continue;
pared[arr[node][i]]=ed[node][i];
f(arr[node][i],node,f);
if (mp[arr[node][i]].size()>mp[node].size()) swap(mp[node],mp[arr[node][i]]);
for (auto it : mp[arr[node][i]]){
mp[node][it.first]+=it.second;
if (mp[node][it.first]==sz[it.first]) mp[node].erase(it.first);
}
mp[arr[node][i]].clear();
}
if (mp[node].size()>=k){
ansarr.push_back(pared[node]);
}
};
f(0,-1,f);
cout<<ansarr.size()<<endl;
sortarr(ansarr);
coutarr(ansarr);
}
}
Compilation message (stderr)
railway.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
railway.cpp: In instantiation of 'main()::<lambda(long long int, long long int, auto:23)> [with auto:23 = main()::<lambda(long long int, long long int, auto:23)>]':
railway.cpp:84:11: required from here
railway.cpp:69:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
railway.cpp:80:23: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
80 | if (mp[node].size()>=k){
| ~~~~~~~~~~~~~~~^~~
# | 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... |