#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n, m;
VI s;
VVI gp;
VI ans;
// n, m <= 2000
namespace TEST1 {
void main() {
rep(r, n) {
VI vis(n);
ll sum = s[r];
vis[r] = true;
priority_queue<PII> pq;
for (int v : gp[r]) pq.push({-s[v], v});
while (pq.size()) {
int u = pq.top().ss;
pq.pop();
if (vis[u]) continue;
if (sum >= s[u]) {
sum += s[u];
vis[u] = true;
for (int v : gp[u]) if (!vis[v]) pq.push({-s[v], v});
} else {
break;
}
}
bool kexni = true;
rep(u, n) if (!vis[u]) kexni = false;
ans[r] = kexni;
}
}
}
// tree
namespace TEST2 {
bool check() {
bool ret = true;
replr(i, 1, n-1) if (s[i] > s[i-1]) ret = false;
rep(u, n) if (u) {
int cnt = 0;
for (int v : gp[u]) if (v < u) cnt++;
if (cnt != 1) ret = false;
}
return ret;
}
VL subsum;
VI par;
VI vat;
void dfs1(int u = 0, int p = -1) {
par[u] = p;
subsum[u] = s[u];
for (int v : gp[u]) if (v != p) {
dfs1(v, u);
subsum[u] += subsum[v];
}
}
void dfs2(int u = 0, int p = -1) {
if (u && vat[p]) vat[u] = true;
for (int v : gp[u]) if (v != p) dfs2(v, u);
}
void main() {
subsum = VL(n);
par = VI(n);
vat = VI(n);
dfs1();
replr(u, 1, n-1) {
if (s[par[u]] > subsum[u]) vat[u] = true;
}
dfs2();
rep(i, n) ans[i] = !vat[i];
}
}
void solve() {
cin >> n >> m;
s = VI(n);
for (int& x : s) cin >> x;
gp = VVI(n);
rep(i, m) {
int u, v;
cin >> u >> v;
u--, v--;
gp[u].pb(v);
gp[v].pb(u);
}
ans = VI(n);
if (n <= 2000 && m <= 2000) TEST1::main();
else if (TEST2::check()) TEST2::main();
for (int x : ans) cout << x; cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
/* cin >> t; */
while (t--) solve();
}
Compilation message
island.cpp: In function 'void solve()':
island.cpp:124:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
124 | for (int x : ans) cout << x; cout << endl;
| ^~~
island.cpp:124:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
124 | for (int x : ans) cout << x; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
177 ms |
608 KB |
Output is correct |
5 |
Correct |
144 ms |
604 KB |
Output is correct |
6 |
Correct |
282 ms |
600 KB |
Output is correct |
7 |
Correct |
189 ms |
600 KB |
Output is correct |
8 |
Correct |
146 ms |
568 KB |
Output is correct |
9 |
Correct |
206 ms |
852 KB |
Output is correct |
10 |
Correct |
53 ms |
600 KB |
Output is correct |
11 |
Correct |
46 ms |
600 KB |
Output is correct |
12 |
Correct |
45 ms |
600 KB |
Output is correct |
13 |
Correct |
83 ms |
600 KB |
Output is correct |
14 |
Correct |
84 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
98 ms |
23892 KB |
Output is correct |
4 |
Correct |
116 ms |
22876 KB |
Output is correct |
5 |
Correct |
128 ms |
18004 KB |
Output is correct |
6 |
Correct |
109 ms |
18768 KB |
Output is correct |
7 |
Correct |
135 ms |
18768 KB |
Output is correct |
8 |
Correct |
128 ms |
18772 KB |
Output is correct |
9 |
Correct |
115 ms |
18516 KB |
Output is correct |
10 |
Correct |
69 ms |
19124 KB |
Output is correct |
11 |
Correct |
67 ms |
19140 KB |
Output is correct |
12 |
Correct |
94 ms |
18128 KB |
Output is correct |
13 |
Correct |
125 ms |
30388 KB |
Output is correct |
14 |
Correct |
124 ms |
30548 KB |
Output is correct |
15 |
Correct |
120 ms |
31404 KB |
Output is correct |
16 |
Correct |
69 ms |
30544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
76 ms |
15868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
74 ms |
14420 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
177 ms |
608 KB |
Output is correct |
5 |
Correct |
144 ms |
604 KB |
Output is correct |
6 |
Correct |
282 ms |
600 KB |
Output is correct |
7 |
Correct |
189 ms |
600 KB |
Output is correct |
8 |
Correct |
146 ms |
568 KB |
Output is correct |
9 |
Correct |
206 ms |
852 KB |
Output is correct |
10 |
Correct |
53 ms |
600 KB |
Output is correct |
11 |
Correct |
46 ms |
600 KB |
Output is correct |
12 |
Correct |
45 ms |
600 KB |
Output is correct |
13 |
Correct |
83 ms |
600 KB |
Output is correct |
14 |
Correct |
84 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
98 ms |
23892 KB |
Output is correct |
18 |
Correct |
116 ms |
22876 KB |
Output is correct |
19 |
Correct |
128 ms |
18004 KB |
Output is correct |
20 |
Correct |
109 ms |
18768 KB |
Output is correct |
21 |
Correct |
135 ms |
18768 KB |
Output is correct |
22 |
Correct |
128 ms |
18772 KB |
Output is correct |
23 |
Correct |
115 ms |
18516 KB |
Output is correct |
24 |
Correct |
69 ms |
19124 KB |
Output is correct |
25 |
Correct |
67 ms |
19140 KB |
Output is correct |
26 |
Correct |
94 ms |
18128 KB |
Output is correct |
27 |
Correct |
125 ms |
30388 KB |
Output is correct |
28 |
Correct |
124 ms |
30548 KB |
Output is correct |
29 |
Correct |
120 ms |
31404 KB |
Output is correct |
30 |
Correct |
69 ms |
30544 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
76 ms |
15868 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |