#include using namespace std; const int MAXN = 100100; int arr[MAXN]; vector edges[MAXN]; vector redges[MAXN]; bool bio[MAXN]; vector topo; int scc[MAXN]; int score[MAXN]; vector cedges[MAXN]; vector topo2; void toposort(int u) { bio[u] = true; for (int v: edges[u]) if (!bio[v]) toposort(v); topo.push_back(u); } void dfs(int u, int root) { scc[u] = root; score[root] = max(score[root], arr[u]); for (int v: redges[u]) if (scc[v] == -1) dfs(v, root); } void toposort2(int u) { bio[u] = true; for (int v: cedges[u]) if (!bio[v]) toposort2(v); topo2.push_back(u); } int main() { freopen("promotion.in", "r", stdin); freopen("promotion.out", "w", stdout); int n, m, i; int u, v; cin>>n>>m; for (i = 0; i < n; ++i) { cin>>arr[i]; scc[i] = -1; score[i] = 0; } for (i = 0; i < m; ++i) { cin>>u>>v; --u, --v; edges[u].push_back(v); redges[v].push_back(u); } fill(bio, bio + n, false); for (i = 0; i < n; ++i) if (!bio[i]) toposort(i); reverse(topo.begin(), topo.end()); for (int u: topo) if (scc[u] == -1) dfs(u, u); for (u = 0; u < n; ++u) { for (int v: edges[u]) cedges[scc[u]].push_back(scc[v]); } fill(bio, bio + n, false); for (i = 0; i < n; ++i) if (!bio[scc[i]]) { toposort2(scc[i]); } for (int c: topo2) { for (int d: cedges[c]) score[c] = max(score[c], score[d]); } for (i = 0; i < n; ++i) cout<