Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
35262 | LYLAKIOIAKIOI | 【J】T2 | C++ | 通过 | 100 | 769 MS | 66880 KB | 734 | 2024-12-08 14:13:52 |
#include<bits/stdc++.h> #define vec vector #define jp8 push_back #define ui32 unsigned int using namespace std; const int N=1e6+10; const ui32 INF=1e9+10; int f[N],a[N]; vec<int> E[N]; bool cmp(int a,int b){ return f[a]<f[b]; } void dfs(int u){ f[u]=min(INF,(ui32)(a[u])); for(auto v:E[u]){ dfs(v);f[u]=min(f[u],f[v]); } }void wt(int u){ if(E[u].size()==0) cout<<a[u]<<' '; sort(E[u].begin(),E[u].end(),cmp); for(auto v:E[u]){ wt(v); } }int n,m; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ int x;cin>>x; while(x--){ int p;cin>>p;E[i].jp8(p); } }dfs(1);wt(1);cout.flush(); return 0; }