#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;
int n;
vector<int> g[N];
int s[N];
bool can[N];
bool check(int v){
queue<int> q;
q.push(v);
vector<bool> used(n, false);
used[v] = true;
ll sum = 0;
set<pair<int, int>> blocked;
while (!q.empty()){
v = q.front();
q.pop();
sum += s[v];
while (!blocked.empty() && blocked.begin()->first <= sum){
int x = blocked.begin()->second;
q.push(x);
used[x] = true;
if (can[x]) return true;
blocked.erase(blocked.begin());
}
for (int u : g[v]){
if (used[u]) continue;
if (s[u] <= sum){
q.push(u);
used[u] = true;
if (can[u]) return true;
} else {
blocked.emplace(s[u], u);
}
}
}
return count(all(used), true) == n;
}
void solve(){
int m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
}
while (m--){
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> perm(n);
iota(all(perm), 0);
sort(all(perm), [&](int i, int j){
return s[i] > s[j];
});
for (int i : perm) can[i] = check(i);
for (int i = 0; i < n; i++){
cout << can[i];
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5076 KB |
Output is correct |
5 |
Correct |
8 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
5 ms |
5076 KB |
Output is correct |
9 |
Correct |
139 ms |
5148 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
6 ms |
5076 KB |
Output is correct |
12 |
Correct |
6 ms |
5076 KB |
Output is correct |
13 |
Correct |
90 ms |
5076 KB |
Output is correct |
14 |
Correct |
33 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Execution timed out |
1083 ms |
12964 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
13012 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1068 ms |
13228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5076 KB |
Output is correct |
5 |
Correct |
8 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
5 ms |
5076 KB |
Output is correct |
9 |
Correct |
139 ms |
5148 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
6 ms |
5076 KB |
Output is correct |
12 |
Correct |
6 ms |
5076 KB |
Output is correct |
13 |
Correct |
90 ms |
5076 KB |
Output is correct |
14 |
Correct |
33 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Execution timed out |
1083 ms |
12964 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |