#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
vector<int> g[N];
int a[N], n, m;
ll cur = 0, cnt = 1;
bool vis[N];
void dfs(int v) {
for(auto u : g[v]) {
if(cur >= a[u] && !vis[u]) {
vis[u] = 1;
cur += a[u];
cnt++;
dfs(u);
}
}
}
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0; i < n; i++) {
sort(g[i].begin(), g[i].end(), [&](int x, int y) {
return a[x] < a[y];
});
}
for(int i = 0; i < n; i++) {
cnt = 1;
vis[i] = 1;
cur = a[i];
dfs(i);
for(int j = 0; j < n; j++) vis[j] = 0;
if(cnt == n) {
cout << '1';
} else {
cout << '0';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5028 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
43 ms |
5128 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Execution timed out |
1081 ms |
20428 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1081 ms |
25828 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
17500 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5028 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
43 ms |
5128 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |