#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pllll pair<ll, ll>
#define size(v) v.size()
#define all(v) v.begin(), v.end()
#define INF 2e9
#define f first
#define s second
using namespace std;
vector<vector<int>>g;
vector<bool>visited;
vector<int>s;
int Sum;
bool comp(int i, int j){
return s[i] < s[j];
}
void dfs(int node, vector<int>&s){
Sum += s[node];
visited[node] = true;
for(int to : g[node]){
if(!visited[to] && s[to] <= Sum){
dfs(to, s);
}
}
}
void solve(){
ll n, m, whole = 0;
cin >> n >> m;
g.resize(n + 1);
s.resize(n + 1);
visited.assign(n + 1, false);
for(int i = 1; i <= n; ++i){
cin >> s[i];
whole += s[i];
}
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1; i <= n; ++i){
sort(all(g[i]), comp);
}
for(int i = 1; i <= n; ++i){
visited.assign(n + 1, false);
Sum = 0;
dfs(i, s);
if(Sum == whole){
cout << 1;
}else{
cout << 0;
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
// cin >> t;
t = 1;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
288 ms |
12300 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
260 ms |
12100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
321 ms |
12272 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |