This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
#define ll long long
int n, m, u, v, s[nx];
vector<int> d[nx];
bool vs[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=n; i++) cin>>s[i];
for (int i=1; i<=m; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
for (int i=1; i<=n; i++)
{
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
ll sz=0, cnt=0;
for (int j=1; j<=n; j++) vs[j]=0;
pq.push({0, i});
while (!pq.empty())
{
int x=pq.top().first, y=pq.top().second;
pq.pop();
if (sz<x||vs[y]) continue;
vs[y]=1;
cnt++;
sz+=s[y];
for (auto nw:d[y])
{
//cout<<i<<' '<<sz<<' '<<nw<<' '<<s[nw]<<'\n';
pq.push({s[nw], nw});
}
}
if (cnt==n) cout<<1;
else cout<<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... |