// ConsoleApplication134.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#include <algorithm>
#include <queue>
#define pll pair<ll,ll>
const int siz = 2e5;
bool ans[siz];
ll cit[siz];
vi fr[siz];
int up[siz];
#include <set>
vector<pll> ord;
int my[siz];
vi col[siz];
ll sum[siz];
set<pll> out[siz];
int num[siz];
void uni(int i, int j) {
i = my[i], j = my[j];
if (i == j)return;
sum[i] += sum[j];
for (pll p : out[j]) {
out[i].insert(p);
}
for (int v : col[j]) {
col[i].push_back(v);
my[v] = i;
}
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> cit[i];
ord.push_back({ cit[i],-i });
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
fr[a].push_back(b);
fr[b].push_back(a);
}
sort(ord.begin(), ord.end());
ans[-ord[n - 1].second] = 1;
for (int i = 0; i < n; i++) {
ord[i].second = -ord[i].second;
num[ord[i].second] = i;
}
for (int i = 0; i < n; i++) {
my[i] = i;
col[i].push_back(i);
sum[i] = cit[i];
for (int f : fr[i]) {
if ( num[f]>num[i]) {
out[i].insert({ cit[f],f });
}
}
}
for (int i = 0; i < n; i++)up[i] = -1;
for (int i = 0; i < n-1; i++) {
int j = ord[i].second;
for (int f : fr[j]) {
if (out[my[f]].find({ cit[j],j }) != out[my[f]].end()) {
out[my[f]].erase({ cit[j],j });
}
}
for (int f : fr[j]) {
if (num[f] < i) {
uni(j, f);
}
}
if (!out[my[j]].empty()) {
pll p = *out[my[j]].begin();
if (p.first <= sum[my[j]]) {
up[j] = p.second;
}
}
}
for (int i = n - 2; i >= 0; i--) {
if (up[ord[i].second] != -1) {
ans[ord[i].second] = ans[up[ord[i].second]];
}
}
for (int i = 0; i < n; i++)if (ans[i])cout << '1'; else cout << '0';
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
11 ms |
19024 KB |
Output is correct |
3 |
Correct |
11 ms |
19028 KB |
Output is correct |
4 |
Correct |
40 ms |
29404 KB |
Output is correct |
5 |
Correct |
15 ms |
20820 KB |
Output is correct |
6 |
Correct |
43 ms |
32652 KB |
Output is correct |
7 |
Correct |
36 ms |
29596 KB |
Output is correct |
8 |
Correct |
33 ms |
29356 KB |
Output is correct |
9 |
Correct |
188 ms |
92460 KB |
Output is correct |
10 |
Correct |
14 ms |
19620 KB |
Output is correct |
11 |
Correct |
15 ms |
19512 KB |
Output is correct |
12 |
Correct |
14 ms |
19500 KB |
Output is correct |
13 |
Correct |
30 ms |
29524 KB |
Output is correct |
14 |
Correct |
15 ms |
20820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
524288 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19092 KB |
Output is correct |
2 |
Correct |
547 ms |
75096 KB |
Output is correct |
3 |
Correct |
591 ms |
76444 KB |
Output is correct |
4 |
Execution timed out |
1057 ms |
524288 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
363760 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
11 ms |
19024 KB |
Output is correct |
3 |
Correct |
11 ms |
19028 KB |
Output is correct |
4 |
Correct |
40 ms |
29404 KB |
Output is correct |
5 |
Correct |
15 ms |
20820 KB |
Output is correct |
6 |
Correct |
43 ms |
32652 KB |
Output is correct |
7 |
Correct |
36 ms |
29596 KB |
Output is correct |
8 |
Correct |
33 ms |
29356 KB |
Output is correct |
9 |
Correct |
188 ms |
92460 KB |
Output is correct |
10 |
Correct |
14 ms |
19620 KB |
Output is correct |
11 |
Correct |
15 ms |
19512 KB |
Output is correct |
12 |
Correct |
14 ms |
19500 KB |
Output is correct |
13 |
Correct |
30 ms |
29524 KB |
Output is correct |
14 |
Correct |
15 ms |
20820 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
10 ms |
19028 KB |
Output is correct |
17 |
Execution timed out |
1082 ms |
524288 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |