#include<bits/stdc++.h>
#define ll long long
#define ff first
#define sd second
using namespace std;
vector<vector<int>>v;
vector<int>a,vis;
int main(){
int n,m;cin>>n>>m;
a.resize(n+1);
v.resize(n+1);
vis.assign(n+1,0);
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=0;i<m;i++){
int x,y;cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1;i<=n;i++){
set<pair<int,int>>s;
s.insert({0,i});
vis[i]=i;
ll sum=0;
while(!s.empty()){
pair<int,int> l=*s.begin();
int cnt=l.ff;
int x=l.sd;
if(cnt>sum) break;
s.erase(s.begin());
sum+=a[x];
for(int z:v[x])
if(vis[z]!=i){
vis[z]=i;
s.insert({a[z],z});
}
}
if(s.empty()) cout<<1;
else cout<<0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
208 ms |
404 KB |
Output is correct |
5 |
Correct |
215 ms |
420 KB |
Output is correct |
6 |
Correct |
296 ms |
340 KB |
Output is correct |
7 |
Correct |
193 ms |
400 KB |
Output is correct |
8 |
Correct |
148 ms |
388 KB |
Output is correct |
9 |
Correct |
311 ms |
468 KB |
Output is correct |
10 |
Correct |
108 ms |
400 KB |
Output is correct |
11 |
Correct |
94 ms |
400 KB |
Output is correct |
12 |
Correct |
115 ms |
340 KB |
Output is correct |
13 |
Correct |
187 ms |
404 KB |
Output is correct |
14 |
Correct |
112 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1071 ms |
14124 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
12692 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1056 ms |
13084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
208 ms |
404 KB |
Output is correct |
5 |
Correct |
215 ms |
420 KB |
Output is correct |
6 |
Correct |
296 ms |
340 KB |
Output is correct |
7 |
Correct |
193 ms |
400 KB |
Output is correct |
8 |
Correct |
148 ms |
388 KB |
Output is correct |
9 |
Correct |
311 ms |
468 KB |
Output is correct |
10 |
Correct |
108 ms |
400 KB |
Output is correct |
11 |
Correct |
94 ms |
400 KB |
Output is correct |
12 |
Correct |
115 ms |
340 KB |
Output is correct |
13 |
Correct |
187 ms |
404 KB |
Output is correct |
14 |
Correct |
112 ms |
408 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
1071 ms |
14124 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |