#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _ <<' '<<
#define print(x) cout<<#x<<": "<<(x)<<'\n'
int n,m;
vector<vector<int>> adj;
vector<array<ll, 2>> s;
vector<int> idx, res, vis;
vector<list<int>> bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
struct dsu{
vector<int> par;
vector<ll> sz;
dsu() {
par.resize(n);
iota(par.begin(), par.end(), 0);
sz.resize(n);
for (int i=0; i<n; i++) sz[i]=s[i][0];
}
int find(const int i) {
if (par[i]==i) return i;
return par[i]=find(par[i]);
}
bool unite(int i, int j) {
j=find(j);
if (s[i][0]>sz[j]) vis[j]=0;
i=find(i);
if (i==j) return false;
bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[i].splice(bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[i].end(), bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[j]);
vis[j]=0;
par[j]=i;
sz[i]+=sz[j];
return true;
}
ll size(const int i) {
return sz[find(i)];
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
cin>>n>>m;
adj.resize(n);
s.resize(n);
res.assign(n, 0);
vis.assign(n, 1);
bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.resize(n);
for (int i=0; i<n; i++) bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[i].push_back(i);
for (int i=0; i<n; i++) {
cin>>s[i][0];
s[i][1]=i;
}
sort(s.begin(), s.end());
idx.resize(n);
for (int i=0; i<n; i++) idx[s[i][1]]=i;
for (int i=0; i<m; i++) {
int a,b;
cin>>a>>b;
a=idx[--a];
b=idx[--b];
if (s[a][0]>s[b][0]) adj[a].push_back(b);
else adj[b].push_back(a);
}
dsu f;
int l=0, r=0, w=0;
while (l<n) {
w=s[l][0];
while (r<n-1 && s[r+1][0]==w) ++r;
++r;
for (int i=l; i<r; i++) for (const auto j:adj[i]) {
f.unite(i, j);
}
l=r;
}
//vis.assign(n, {0,0});
int ptr=-1;
for (const auto &e:bwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa){
for (const auto d:e) if (vis[++ptr]) {
cout<<d _ s[d][1] _ 'a'<<'\n';
res[s[d][1]]=1;
}
}
for (const auto e:res) cout<<!e;
cout<<'\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |