Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- const int wh=0, gr=1, bl=2;
- vector <int> tm;//time per det
- ll tot=0; // tot time
- vector <vector<int> > G;
- vector <int> ans;
- vector <int> clr;
- void dfs(int v){
- tot += tm[v];
- clr[v] = gr;
- for (int u: G[v]){
- if (clr[u] == wh) dfs(u);
- }
- ans.push_back(v+1);
- clr[v] = bl;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n,k;
- cin>>n;
- G.resize(n);
- tm.resize(n);
- clr.assign(n, wh);
- for (int &x: tm) cin>>x;
- for (int i = 0; i < n;++i){
- cin>>k;
- for (int j=0;j<k;++j){
- int d; cin>>d; d--;
- G[i].push_back(d);
- }
- }
- dfs(0);
- cout<<tot<<' '<<ans.size()<<' '<<"\n";
- cv(ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement