#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
vector<vector<int>> adj;
vector<int> v;int n,m;
bool ok(int x){
vector<int> vis(n+2,0);
vis[x] = 1;
int sum = v[x];
priority_queue<ii, vector<ii>, greater<ii>> q;
for(auto i: adj[x]){vis[i] = 1; q.push({v[i], i});}
while(!q.empty()){
int val = q.top().first, id = q.top().second;
q.pop();
if(sum < val) return 0;
for(auto k: adj[id]){
if(vis[k]) continue;
q.push({v[k], k});
vis[k] = 1;
}
sum += val;
}
return true;
}
signed main(){
cin >> n >> m;
v.resize(n+2); adj.resize(n+2);
for(int i=1; i<=n; i++) cin >> v[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++){
if(ok(i))cout << 1;
else cout <<0;
}
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
141 ms |
604 KB |
Output is correct |
5 |
Correct |
131 ms |
608 KB |
Output is correct |
6 |
Correct |
181 ms |
600 KB |
Output is correct |
7 |
Correct |
137 ms |
600 KB |
Output is correct |
8 |
Correct |
99 ms |
344 KB |
Output is correct |
9 |
Correct |
161 ms |
604 KB |
Output is correct |
10 |
Correct |
49 ms |
600 KB |
Output is correct |
11 |
Correct |
47 ms |
600 KB |
Output is correct |
12 |
Correct |
43 ms |
600 KB |
Output is correct |
13 |
Correct |
87 ms |
344 KB |
Output is correct |
14 |
Correct |
81 ms |
852 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 |
Execution timed out |
1083 ms |
20752 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1082 ms |
14324 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
15600 KB |
Time limit exceeded |
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 |
141 ms |
604 KB |
Output is correct |
5 |
Correct |
131 ms |
608 KB |
Output is correct |
6 |
Correct |
181 ms |
600 KB |
Output is correct |
7 |
Correct |
137 ms |
600 KB |
Output is correct |
8 |
Correct |
99 ms |
344 KB |
Output is correct |
9 |
Correct |
161 ms |
604 KB |
Output is correct |
10 |
Correct |
49 ms |
600 KB |
Output is correct |
11 |
Correct |
47 ms |
600 KB |
Output is correct |
12 |
Correct |
43 ms |
600 KB |
Output is correct |
13 |
Correct |
87 ms |
344 KB |
Output is correct |
14 |
Correct |
81 ms |
852 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
1083 ms |
20752 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |