이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 200005;
int n, m;
long long people[maxn];
vector<int> g[maxn];
bool answer[maxn];
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
cin >> people[i];
}
for (int i = 1; i <= m; ++i)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= n; ++i)
{
long long sum = people[i];
vector<bool> visited(n + 5, false);
visited[i] = true;
priority_queue<pair<long long, int>> pq;
pq.push(make_pair(0, i));
bool flag = true;
while (!pq.empty())
{
pair<long long, int> p = pq.top();
pq.pop();
long long curr = -p.first;
int node = p.second;
visited[node] = true;
if (sum < curr)
{
flag = false;
break;
}
sum += curr;
for (auto next_node : g[node])
{
if (visited[next_node] == false)
{
pq.push(make_pair(-people[next_node], next_node));
}
}
}
for (int j = 1; j <= n; ++j)
{
if (visited[i] == false)
{
flag = false;
break;
}
}
answer[i] = flag;
}
for (int i = 1; i <= n; ++i)
{
cout << answer[i];
}
cout << endl;
return 0;
}
# | 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... |