#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;
ll Sum;
vector<int>s;
vector<vector<int>>g;
vector<bool>visited;
bool comp(int i, int j){
return s[i] < s[j];
}
void dfs_sub1(int node){
visited[node] = true;
for(int to : g[node]){
if(!visited[to] && Sum >= s[to]){
Sum += s[to];
dfs_sub1(to);
}
}
}
void Sub1(int n, int m, int SUM){
string Res = "";
for(int i = 1; i <= n; ++i){
Sum = s[i];
dfs_sub1(i);
if(Sum == SUM){
Res += '1';
}else{
Res += '0';
}
visited.assign(n + 1, false);
}
cout << Res << "\n";
}
void solve(){
ll n, m, SUM = 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];
SUM += 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);
}
if(n <= 2000 && m <= 2000){
Sub1(n, m, SUM);
}
}
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 |
1 ms |
320 KB |
Output is correct |
4 |
Incorrect |
45 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
115 ms |
12236 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 |
101 ms |
12144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Incorrect |
140 ms |
12224 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 |
1 ms |
320 KB |
Output is correct |
4 |
Incorrect |
45 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |