#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2001;
ll S[maxn];
vector <int> adj[maxn];
bool vis[maxn];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> S[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
ll sz = S[i];
fill(vis, vis + n + 1, false);
vis[i] = true;
priority_queue <pair <ll, int>> pq;
for (auto j : adj[i]) {
pq.push({-S[j], j});
vis[j] = true;
}
int x = 1;
while (!pq.empty()) {
ll tp = -pq.top().first;
int s = pq.top().second;
pq.pop();
if (tp > sz)
break;
sz += tp;
x++;
for (auto j : adj[s]) {
if (vis[j])
continue;
pq.push({-S[j], j});
vis[j] = true;
}
}
if (x == n)
cout << 1;
else
cout << 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
125 ms |
348 KB |
Output is correct |
5 |
Correct |
114 ms |
600 KB |
Output is correct |
6 |
Correct |
179 ms |
344 KB |
Output is correct |
7 |
Correct |
124 ms |
600 KB |
Output is correct |
8 |
Correct |
87 ms |
568 KB |
Output is correct |
9 |
Correct |
175 ms |
604 KB |
Output is correct |
10 |
Correct |
48 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
604 KB |
Output is correct |
12 |
Correct |
39 ms |
348 KB |
Output is correct |
13 |
Correct |
83 ms |
344 KB |
Output is correct |
14 |
Correct |
67 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
125 ms |
348 KB |
Output is correct |
5 |
Correct |
114 ms |
600 KB |
Output is correct |
6 |
Correct |
179 ms |
344 KB |
Output is correct |
7 |
Correct |
124 ms |
600 KB |
Output is correct |
8 |
Correct |
87 ms |
568 KB |
Output is correct |
9 |
Correct |
175 ms |
604 KB |
Output is correct |
10 |
Correct |
48 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
604 KB |
Output is correct |
12 |
Correct |
39 ms |
348 KB |
Output is correct |
13 |
Correct |
83 ms |
344 KB |
Output is correct |
14 |
Correct |
67 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |