#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 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 val[MAXN];
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;
ll mx = 0;
for (int i = 1; i <= n; i++)
{
cin >> val[i];
par[i] = i;
pq.push({val[i], i});
mx = max(mx, val[i]);
}
for (int i = 1; i <= m; i++)
{
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (!pq.empty())
{
auto [va, idx] = pq.top();
// cout << ":: " << va << ' ' << idx << endl;
pq.pop();
vis[idx] = 1;
if (va != val[fpar(par[idx])])
continue;
for (int i : adj[idx])
{
if (!vis[i] and val[fpar(par[idx])] >= val[fpar(par[i])])
{
vis[i] = 1;
val[i] += va;
par[idx] = fpar(par[i]);
pq.push({val[i], i});
}
}
}
for (int i = 1; i <= n; i++)
{
if (val[fpar(par[i])] >= mx)
cout << 1;
else
cout << 0;
}
cout << endl;
// for (int i = 1; i <= n; i++)
// {
// cout << par[i] << ' ';
// }
// cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
147 ms |
17124 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
179 ms |
17068 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
198 ms |
17044 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |