#include <bits/stdc++.h>   using namespace std;   int read() {     int x;     scanf( %d , &x);     return x;   }   const int N = 1123456;   int a[N];   vector<int> v[N];   int c[N];   priority_queue<int> q[N];   void dfs(int x, int t) {     c[x] = t;     q[t].push(a[x]);     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (!c[to]) {         dfs(to, t);       }     }   }   int main() {     int n, m, i, j, x, y;     n = read();     m = read();     for (i = 1; i <= n; i++) {       a[i] = read();     }     for (i = 1; i <= m; i++) {       x = read();       y = read();       v[x].push_back(y);       v[y].push_back(x);     }     int cnt = 1;     for (i = 1; i <= n; i++) {       if (!c[i]) {         dfs(i, cnt++);       }     }     for (i = 1; i <= n; i++) {       printf( %d  , q[c[i]].top());       q[c[i]].pop();     }   }   