#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<ll>>g;
vector<bool>visited;
vector<ll>s;
ll Sum;
bool comp(int i, int j){
return s[i] < s[j];
}
void dfs(int node, vector<ll>&s){
Sum += s[node];
visited[node] = true;
for(int to : g[node]){
if(!visited[to] && Sum >= s[to]){
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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
45 ms |
468 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 |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
17488 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
22008 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
14608 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
45 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |