#include #define filein(str) freopen(str, "r", stdin) #define fileout(str) freopen(str, "w", stdout); using namespace std; vector gr[100005]; pair nodes[100005]; bool used[100005]; long long ans[100005]; void dfs(int node, int sal) { used[node] = true; ans[node] = sal; for(int i = 0; i < gr[node].size(); i++) if(!used[gr[node][i]]) dfs(gr[node][i], sal); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); filein("promotion.in"); fileout("promotion.out"); int n, m; cin >> n >> m; for(int i = 0; i < n; i++) { cin >> nodes[i].first; nodes[i].second = i; } sort(nodes, nodes + n); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; gr[b].push_back(a); } for(int i = n - 1; i >= 0; i--) { if(!used[nodes[i].second]) { dfs(nodes[i].second, nodes[i].first); } } for(int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; return 0; }