#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 1e6 + 5;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n, m, u, v;
vi adj[MAXN];
int par[MAXN];
ll s[MAXN], val[MAXN], mx;
bool vis[MAXN];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
int fpar(int a)
{
return par[a] = (par[a] == a ? a : fpar(par[a]));
}
int main()
{
gl;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> s[i];
val[i] = s[i];
pq.push({s[i], i});
par[i] = i;
mx = max(mx, s[i]);
}
for (int i = 0; i < m; i++)
{
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (!pq.empty())
{
auto [va, idx] = pq.top();
pq.pop();
if (vis[idx] or va != val[fpar(idx)])
continue;
vis[idx] = 1;
for (int i : adj[idx])
{
if (val[idx] >= s[i])
{
vis[i] = 1;
par[i] = idx;
val[idx] += s[i];
pq.push({val[idx], idx});
break;
}
}
}
for (int i = 1; i <= n; i++)
{
if (val[fpar(i)] >= mx)
cout << 1;
else
cout << 0;
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23788 KB |
Output is correct |
4 |
Incorrect |
14 ms |
23920 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
12 ms |
23740 KB |
Output is correct |
3 |
Incorrect |
203 ms |
37800 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23816 KB |
Output is correct |
2 |
Incorrect |
225 ms |
37660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Incorrect |
278 ms |
37728 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23788 KB |
Output is correct |
4 |
Incorrect |
14 ms |
23920 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |