This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
4 3
4 2 2 1
1 2
3 2
4 1
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
int S[N];
for (int i = 0; i < N; i++)
cin >> S[i];
vector<int>adj[N];
while (M--)
{
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<bool>ret(N, false);
for (int i = 0; i < N; i++)
{
vector<bool>vis(N, false);
vis[i] = true;
ll sum = S[i];
set<pair<int, int>>Q;
for (int j : adj[i])
{
vis[j] = true;
Q.insert({S[j], j});
}
int cnt = 1;
while (!Q.empty())
{
int i = Q.begin()->second;
Q.erase(Q.begin());
if (S[i] <= sum)
{
sum += S[i];
cnt++;
for (int j : adj[i])
{
if (vis[j] == false)
{
vis[j] = true;
Q.insert({S[j], j});
}
}
}
else
break;
}
if (cnt == N)
ret[i] = true;
}
for (int i : ret)
cout << i;
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |