#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int N;
vector<vector<int>> adj;
vector<int> cnt;
vector<bool> vis;
long long curr = 0;
void dfs(int pos) {
vis[pos] = true;
curr += cnt[pos];
for (auto &v: adj[pos]) {
if (vis[v] || cnt[v] > curr) continue;
dfs(v);
}
}
bool comp(int a, int b) {
return cnt[a] < cnt[b];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int M;
cin >> N >> M;
cnt.resize(N + 1);
for (int i = 1; i <= N; i++) cin >> cnt[i];
adj.resize(N + 1);
for (int i = 0, u, v; i < M; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= N; i++) {
sort(adj[i].begin(), adj[i].end(), comp);
}
string res;
vis.resize(N + 1);
for (int i = 1; i <= N; i++) {
fill(vis.begin(), vis.end(), false);
curr = 0;
dfs(i);
bool ok = true;
for (int i = 1; i <= N; i++) {
if (!vis[i]) {
ok = false;
break;
}
}
res.push_back((ok ? '1' : '0'));
}
cout << res;
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 |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
50 ms |
416 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 |
1072 ms |
14704 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
18132 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 |
1062 ms |
12700 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 |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
50 ms |
416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |