#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz size()
using namespace std;
const double pi = 2 * acos(0.0);
const ll N=1e6+7, M=998244353;
vector <ll> g[N];
ll a[N], res[N];
bool u[N];
ll sum[N], ans[N];
ll dfs(int v){
sum[v]=a[v];
u[v]=1;
for (auto l:g[v]){
if (!u[l]){
sum[v]+=dfs(l);
}
}
return sum[v];
}
void dfs1(int v){
u[v]=1;
if (sum[v] >= a[res[v]] && ans[res[v]]) ans[v]=1;
else{
if (v != 1) return ;
}
for (auto l:g[v]){
if (!u[l]){
res[l]=v;
dfs1(l);
}
}
return ;
}
void solve()
{
int n, m;
cin >> n >> m;
for (int i=1;i<=n;i++) cin >> a[i];
for (int i=1;i<=m;i++){
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
if (n <= 2000 && m <= 2000){
for (int i=1;i<=n;i++){
set <pair <ll, ll>> q;
vector <int> u(n+5, 0);
q.insert({0, i});
ll sum=0, cnt=0;
while (!q.empty()){
pair <ll,ll> mn=*q.begin();
if (sum < mn.ff) break;
if (u[mn.ss]) continue;
u[mn.ss]=1;
q.erase(mn);
sum+=a[mn.ss];
for (auto l:g[mn.ss]){
if (!u[l]) {
q.insert({a[l], l});
}
}
}
if (q.sz == 0) cout << "1";
else cout << "0";
}
return ;
}
ans[1]=1;
dfs(1);
fill(u, u+n+5, 0);
dfs1(1);
for (int i=1;i<=n;i++) cout << ans[i] << " ";
return;
}
int main(){
ios;
int t=1;
// cin >> t;
while (t--){
solve();
cout << "\n";
}
return 0;
}
Compilation message
island.cpp: In function 'void solve()':
island.cpp:61:14: warning: unused variable 'cnt' [-Wunused-variable]
61 | ll sum=0, cnt=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23780 KB |
Output is correct |
3 |
Correct |
14 ms |
23708 KB |
Output is correct |
4 |
Correct |
316 ms |
23916 KB |
Output is correct |
5 |
Correct |
282 ms |
23856 KB |
Output is correct |
6 |
Correct |
458 ms |
23908 KB |
Output is correct |
7 |
Correct |
301 ms |
23892 KB |
Output is correct |
8 |
Correct |
226 ms |
23908 KB |
Output is correct |
9 |
Correct |
503 ms |
23964 KB |
Output is correct |
10 |
Correct |
133 ms |
23892 KB |
Output is correct |
11 |
Correct |
128 ms |
23892 KB |
Output is correct |
12 |
Correct |
163 ms |
23912 KB |
Output is correct |
13 |
Correct |
257 ms |
23892 KB |
Output is correct |
14 |
Correct |
164 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23724 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
166 ms |
42840 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Incorrect |
160 ms |
49428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23712 KB |
Output is correct |
2 |
Incorrect |
192 ms |
38828 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23780 KB |
Output is correct |
3 |
Correct |
14 ms |
23708 KB |
Output is correct |
4 |
Correct |
316 ms |
23916 KB |
Output is correct |
5 |
Correct |
282 ms |
23856 KB |
Output is correct |
6 |
Correct |
458 ms |
23908 KB |
Output is correct |
7 |
Correct |
301 ms |
23892 KB |
Output is correct |
8 |
Correct |
226 ms |
23908 KB |
Output is correct |
9 |
Correct |
503 ms |
23964 KB |
Output is correct |
10 |
Correct |
133 ms |
23892 KB |
Output is correct |
11 |
Correct |
128 ms |
23892 KB |
Output is correct |
12 |
Correct |
163 ms |
23912 KB |
Output is correct |
13 |
Correct |
257 ms |
23892 KB |
Output is correct |
14 |
Correct |
164 ms |
23900 KB |
Output is correct |
15 |
Correct |
13 ms |
23724 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Incorrect |
166 ms |
42840 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |