#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 7;
int n, m;
ll mx;
ll s[N];
vector <int> d[N];
namespace sub14 {
vector <int> save;
bool vis[N];
bool check(int st) {
priority_queue <pii, vector <pii>, greater <pii>> q;
for (int i: save) vis[i] = false;
save.clear();
for (int u: d[st]) {
vis[u] = true;
save.push_back(u);
q.push({s[u], u});
}
ll cur = s[st];
vis[st] = true;
save.push_back(st);
ll tar = mx;
while (q.size()) {
int u = q.top().nd, w = q.top().st; q.pop();
if (cur < w) return false;
cur += w;
if (cur >= tar) return true;
for (int v: d[u]) if (!vis[v]) {
vis[v] = true;
save.push_back(v);
q.push({s[v], v});
}
}
return true;
}
}
namespace sub2 {
bool ck[N];
ll f[N];
void dfs(int p, int u) {
f[u] = s[u];
for (int v: d[u]) if (v != p) {
dfs(u, v);
f[u] += f[v];
}
ck[u] = f[u] >= s[p];
}
void dfs2(int p, int u) {
for (int v: d[u]) if (v != p) {
ck[v] &= ck[u];
dfs2(u, v);
}
}
void solve() {
ck[1] = true;
dfs(1, 1);
dfs2(1, 1);
rep(i, 1, n) cout << ck[i];
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
rep(i, 1, n) {
cin >> s[i];
mx = max(mx, s[i]);
}
rep(i, 1, m) {
int u, v;
cin >> u >> v;
d[u].push_back(v);
d[v].push_back(u);
}
bool is_sub2 = true;
if (m != n - 1) is_sub2 = false;
rep(i, 2, n) if (s[i] > s[i - 1]) is_sub2 = false;
if (is_sub2) {
sub2::solve();
return 0;
}
rep(i, 1, n)
cout << sub14 :: check(i);
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
226 ms |
5140 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5112 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
130 ms |
5076 KB |
Output is correct |
14 |
Correct |
101 ms |
5124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
142 ms |
20956 KB |
Output is correct |
4 |
Correct |
136 ms |
21036 KB |
Output is correct |
5 |
Correct |
150 ms |
14532 KB |
Output is correct |
6 |
Correct |
160 ms |
14772 KB |
Output is correct |
7 |
Correct |
155 ms |
14840 KB |
Output is correct |
8 |
Correct |
185 ms |
14852 KB |
Output is correct |
9 |
Correct |
137 ms |
14740 KB |
Output is correct |
10 |
Correct |
86 ms |
15476 KB |
Output is correct |
11 |
Correct |
86 ms |
15516 KB |
Output is correct |
12 |
Correct |
165 ms |
14836 KB |
Output is correct |
13 |
Correct |
135 ms |
30444 KB |
Output is correct |
14 |
Correct |
131 ms |
30332 KB |
Output is correct |
15 |
Correct |
146 ms |
30556 KB |
Output is correct |
16 |
Correct |
83 ms |
30116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
135 ms |
13160 KB |
Output is correct |
3 |
Correct |
149 ms |
13152 KB |
Output is correct |
4 |
Correct |
136 ms |
30332 KB |
Output is correct |
5 |
Execution timed out |
1085 ms |
14328 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
179 ms |
13204 KB |
Output is correct |
3 |
Correct |
169 ms |
13196 KB |
Output is correct |
4 |
Correct |
152 ms |
13300 KB |
Output is correct |
5 |
Correct |
140 ms |
13260 KB |
Output is correct |
6 |
Correct |
131 ms |
12900 KB |
Output is correct |
7 |
Correct |
112 ms |
19572 KB |
Output is correct |
8 |
Execution timed out |
1094 ms |
17684 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
226 ms |
5140 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5112 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
130 ms |
5076 KB |
Output is correct |
14 |
Correct |
101 ms |
5124 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
142 ms |
20956 KB |
Output is correct |
18 |
Correct |
136 ms |
21036 KB |
Output is correct |
19 |
Correct |
150 ms |
14532 KB |
Output is correct |
20 |
Correct |
160 ms |
14772 KB |
Output is correct |
21 |
Correct |
155 ms |
14840 KB |
Output is correct |
22 |
Correct |
185 ms |
14852 KB |
Output is correct |
23 |
Correct |
137 ms |
14740 KB |
Output is correct |
24 |
Correct |
86 ms |
15476 KB |
Output is correct |
25 |
Correct |
86 ms |
15516 KB |
Output is correct |
26 |
Correct |
165 ms |
14836 KB |
Output is correct |
27 |
Correct |
135 ms |
30444 KB |
Output is correct |
28 |
Correct |
131 ms |
30332 KB |
Output is correct |
29 |
Correct |
146 ms |
30556 KB |
Output is correct |
30 |
Correct |
83 ms |
30116 KB |
Output is correct |
31 |
Correct |
3 ms |
5032 KB |
Output is correct |
32 |
Correct |
135 ms |
13160 KB |
Output is correct |
33 |
Correct |
149 ms |
13152 KB |
Output is correct |
34 |
Correct |
136 ms |
30332 KB |
Output is correct |
35 |
Execution timed out |
1085 ms |
14328 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |