이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |