#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
void setIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
vector<vector<int> > graph;
vector<ll> sub;
vector<bool> ans;
vector<int> val;
void get_sub(int u, int p) {
sub[u] = val[u];
for(int &v : graph[u]) {
if(v == p) continue;
get_sub(v, u);
sub[u] += sub[v];
}
}
void dfs(int u, int p) {
if(sub[u] >= val[p] && ans[p] == 1) ans[u] = 1;
for(int &v : graph[u]) {
if(v == p) continue;
dfs(v, u);
}
}
int32_t main() {
setIO();
int n, m;
cin >> n >> m;
val.resize(n+1);
for(int i=1; i<=n; i++) cin >> val[i];
graph.resize(n+1);
for(int i=0; i<m; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
if(n <= 2000 && m <= 2000) {
auto dijkstra = [&](int a) {
//cout << a << ": \n";
int cnt = 0;
ll total = 0;
vector<bool> vis(n+1);
priority_queue<pll, vector<pll>, greater<pll> > pq;
pq.push({ 0, a });
while(!pq.empty()) {
int u = pq.top().second;
pq.pop();
//cout << u << '\n';
if(vis[u] || (total < val[u] && u != a)) continue;
vis[u] = true;
total += val[u];
cnt++;
for(int &v : graph[u]) {
if(vis[v]) continue;
pq.push({ val[v], v });
}
}
return (cnt == n);
};
for(int i=1; i<=n; i++)
cout << dijkstra(i);
return 0;
}
sub.resize(n+1);
ans.resize(n+1);
get_sub(1, 0);
ans[1] = 1;
dfs(1, 1);
for(int i=1; i<=n; i++)
cout << ans[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
197 ms |
584 KB |
Output is correct |
5 |
Correct |
130 ms |
600 KB |
Output is correct |
6 |
Correct |
239 ms |
604 KB |
Output is correct |
7 |
Correct |
186 ms |
592 KB |
Output is correct |
8 |
Correct |
139 ms |
344 KB |
Output is correct |
9 |
Correct |
201 ms |
608 KB |
Output is correct |
10 |
Correct |
54 ms |
592 KB |
Output is correct |
11 |
Correct |
48 ms |
604 KB |
Output is correct |
12 |
Correct |
43 ms |
604 KB |
Output is correct |
13 |
Correct |
90 ms |
348 KB |
Output is correct |
14 |
Correct |
78 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
107 ms |
20200 KB |
Output is correct |
4 |
Correct |
83 ms |
20564 KB |
Output is correct |
5 |
Correct |
151 ms |
17744 KB |
Output is correct |
6 |
Correct |
90 ms |
18332 KB |
Output is correct |
7 |
Correct |
113 ms |
18264 KB |
Output is correct |
8 |
Correct |
147 ms |
18292 KB |
Output is correct |
9 |
Correct |
75 ms |
18256 KB |
Output is correct |
10 |
Correct |
59 ms |
18240 KB |
Output is correct |
11 |
Correct |
69 ms |
18116 KB |
Output is correct |
12 |
Correct |
113 ms |
16976 KB |
Output is correct |
13 |
Correct |
81 ms |
26124 KB |
Output is correct |
14 |
Correct |
124 ms |
26236 KB |
Output is correct |
15 |
Correct |
125 ms |
28140 KB |
Output is correct |
16 |
Correct |
76 ms |
26852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
89 ms |
25680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1059 ms |
466836 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
197 ms |
584 KB |
Output is correct |
5 |
Correct |
130 ms |
600 KB |
Output is correct |
6 |
Correct |
239 ms |
604 KB |
Output is correct |
7 |
Correct |
186 ms |
592 KB |
Output is correct |
8 |
Correct |
139 ms |
344 KB |
Output is correct |
9 |
Correct |
201 ms |
608 KB |
Output is correct |
10 |
Correct |
54 ms |
592 KB |
Output is correct |
11 |
Correct |
48 ms |
604 KB |
Output is correct |
12 |
Correct |
43 ms |
604 KB |
Output is correct |
13 |
Correct |
90 ms |
348 KB |
Output is correct |
14 |
Correct |
78 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
107 ms |
20200 KB |
Output is correct |
18 |
Correct |
83 ms |
20564 KB |
Output is correct |
19 |
Correct |
151 ms |
17744 KB |
Output is correct |
20 |
Correct |
90 ms |
18332 KB |
Output is correct |
21 |
Correct |
113 ms |
18264 KB |
Output is correct |
22 |
Correct |
147 ms |
18292 KB |
Output is correct |
23 |
Correct |
75 ms |
18256 KB |
Output is correct |
24 |
Correct |
59 ms |
18240 KB |
Output is correct |
25 |
Correct |
69 ms |
18116 KB |
Output is correct |
26 |
Correct |
113 ms |
16976 KB |
Output is correct |
27 |
Correct |
81 ms |
26124 KB |
Output is correct |
28 |
Correct |
124 ms |
26236 KB |
Output is correct |
29 |
Correct |
125 ms |
28140 KB |
Output is correct |
30 |
Correct |
76 ms |
26852 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
89 ms |
25680 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |