//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...); }
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define maxc 31
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
vector<int> adj[maxn];
ll sum[maxc][maxn], mi[maxc][maxn], comp[maxc][maxn];
ll w[maxn];
int lev[maxn];
bool vis[maxn], tv[maxn];
void dfs(int n, int id, int l) {
vis[n] = 1;
sum[l][id] += w[n];
comp[l][n] = id;
for (int v:adj[n]) {
if (!vis[v] && lev[v] < l) dfs(v, id, l);
}
}
int main() {
io
int n, m;
cin >> n >> m;
ll tot = 0;
for (int i = 1;i <= n;i++) cin >> w[i], tot += w[i];
for (int i = 0;i < m;i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1;i <= n;i++) {
ll tmp = w[i];
while (tmp >= 2) {
lev[i]++;
tmp >>= 1;
}
}
for (int j = 0;j <= n;j++) mi[0][j] = inf;
for (int i = 1;i < maxc;i++) {
for (int j = 1;j <= n;j++) vis[j] = 0, mi[i][j] = inf;
mi[i][0] = inf;
int c = 1;
for (int j = 1;j <= n;j++) {
if (!vis[j] && lev[j] < i) {
dfs(j, c, i);
debug(i, j, c, sum[i][c]);
c++;
}
}
for (int j = 1;j <= n;j++) {
if (lev[j] >= i) {
for (int k:adj[j]) {
if (lev[k] < i) mi[i][comp[i][k]] = min(mi[i][comp[i][k]], w[j]);
}
}
}
}
string ans;
for (int i = 1;i <= n;i++) {
int cur = lev[i];
bool poss = 0, fi = 1;
while (cur < maxc) {
ll p = 0, val = inf;
if (fi) {
fi = 0;
p = w[i];
vector<int> v;
for (int j:adj[i]) {
if (lev[j] < cur && !tv[comp[cur][j]]) {
int c = comp[cur][j];
tv[c] = 1;
p += sum[cur][c];
v.push_back(c);
val = min(val, mi[cur][c]);
} else if (lev[j] >= cur) {
val = min(val, w[j]);
}
}
for (int j:v) tv[j] = 0;
} else {
val = min(val, mi[cur][comp[cur][i]]);
}
if (comp[cur][i]) p += sum[cur][comp[cur][i]];
debug(cur, p, val);
if (p == tot) {
poss = 1;
break;
} else if (p < val) {
break;
} else {
cur++;
}
}
debug();
if (poss) ans += '1';
else ans += '0';
}
cout << ans << "\n";
}
/*
6 7
8 5 4 4 6 20
1 2
1 3
1 4
2 3
2 4
1 5
5 6
*/
Compilation message
island.cpp: In function 'int main()':
island.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
island.cpp:64:5: note: in expansion of macro 'debug'
64 | debug(i, j, c, sum[i][c]);
| ^~~~~
island.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
island.cpp:102:4: note: in expansion of macro 'debug'
102 | debug(cur, p, val);
| ^~~~~
island.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
island.cpp:112:3: note: in expansion of macro 'debug'
112 | debug();
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5588 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
3 ms |
5588 KB |
Output is correct |
4 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5588 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
257 ms |
71660 KB |
Output is correct |
4 |
Correct |
538 ms |
109320 KB |
Output is correct |
5 |
Incorrect |
408 ms |
66248 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5588 KB |
Output is correct |
2 |
Incorrect |
278 ms |
93512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5588 KB |
Output is correct |
2 |
Incorrect |
384 ms |
74448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5588 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
3 ms |
5588 KB |
Output is correct |
4 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |