#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#define int long long
#define pii pair <int, int>
using namespace std;
//ifstream fin("input.in");
//ofstream fout("output.out");
#define fin cin
#define fout cout
const int NMAX = 2e5;
int v[NMAX + 1];
vector <int> adj[NMAX + 1];
int par[NMAX + 1];
int sum[NMAX + 1];
bool bad[NMAX + 1];
int Find(int x){
if(x == par[x]){
return x;
}
int y = Find(par[x]); // ?
bad[x] |= bad[par[x]];
par[x] = y;
return par[x];
}
void Join(int x, int y){
x = par[x];
y = par[y];
if(v[x] < v[y]){
swap(x, y);
}
if(v[x] > sum[y]){
bad[y] = 1;
}
par[y] = x;
sum[x] += sum[y];
}
bool ins[NMAX + 1];
void Insert(int x){
ins[x] = true;
for(int vec : adj[x]){
if(ins[vec]){
Join(vec, x);
}
}
}
vector <int> inds[NMAX + 1];
pii e[NMAX + 1];
signed main(){
int n, m;
cin >> n >> m;
vector <int> vals;
for(int i = 1; i <= n; i++){
cin >> v[i];
par[i] = i;
sum[i] = v[i];
vals.push_back(v[i]);
}
vector <pii> aux;
for(int i = 1; i <= m; i++){
int a, b;
fin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
e[i] = {a, b};
aux.push_back({max(v[a], v[b]), i});
}
sort(aux.begin(), aux.end());
for(pii x : aux){
Join(e[x.second].first, e[x.second].second);
}
for(int i = 1; i <= n; i++){
Find(i);
cout << !bad[i];
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14808 KB |
Output is correct |
4 |
Incorrect |
4 ms |
14940 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
231 ms |
31096 KB |
Output is correct |
4 |
Incorrect |
174 ms |
33140 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Incorrect |
205 ms |
31164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Incorrect |
220 ms |
29952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14808 KB |
Output is correct |
4 |
Incorrect |
4 ms |
14940 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |