#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+10;
#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 |
1 |
Correct |
1 ms |
756 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
282 ms |
556 KB |
Output is correct |
5 |
Correct |
223 ms |
600 KB |
Output is correct |
6 |
Correct |
386 ms |
600 KB |
Output is correct |
7 |
Correct |
286 ms |
600 KB |
Output is correct |
8 |
Correct |
223 ms |
576 KB |
Output is correct |
9 |
Correct |
343 ms |
612 KB |
Output is correct |
10 |
Correct |
104 ms |
600 KB |
Output is correct |
11 |
Correct |
98 ms |
600 KB |
Output is correct |
12 |
Correct |
98 ms |
600 KB |
Output is correct |
13 |
Correct |
281 ms |
608 KB |
Output is correct |
14 |
Correct |
145 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
756 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
282 ms |
556 KB |
Output is correct |
5 |
Correct |
223 ms |
600 KB |
Output is correct |
6 |
Correct |
386 ms |
600 KB |
Output is correct |
7 |
Correct |
286 ms |
600 KB |
Output is correct |
8 |
Correct |
223 ms |
576 KB |
Output is correct |
9 |
Correct |
343 ms |
612 KB |
Output is correct |
10 |
Correct |
104 ms |
600 KB |
Output is correct |
11 |
Correct |
98 ms |
600 KB |
Output is correct |
12 |
Correct |
98 ms |
600 KB |
Output is correct |
13 |
Correct |
281 ms |
608 KB |
Output is correct |
14 |
Correct |
145 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |