#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector s(n, 0);
for (int& i : s) cin >> i;
vector<int> ix(n);
for (int i{}; i < n ;i++) ix[i] = i;
stable_sort(ix.begin(), ix.end(), [&](int a, int b) {
return s[a] > s[b];
});
vector<int> jx(n);
for (int i = 0; i < n; i ++)
jx[ix[i]] = i;
stable_sort(s.begin(), s.end(), greater{});
vector<vector<int>> adj(n);
for (int i = 0; i < m ;i++) {
int u, v;
cin >> u >> v;
u--;v--;
adj[jx[u]].push_back(jx[v]);
adj[jx[v]].push_back(jx[u]);
}
//for (int i : ix) cout << i << ' ';cout << endl;
//for (int i : jx) cout << i << ' ';cout << endl;
//for (int i : s) cout << i << ' ';cout << endl;
string res(n, '?');
for (int i = 0; i < n; i++) {
set<pair<int,int>> st;
vector vis(n, 0);
st.emplace(0, i);
vis[i] = 1;
ll sum = s[i];
while (st.size()) {
auto [w, j] = *st.begin();
if (sum < w) break;
if (j < i) {
res[i] = res[j];
break;
}
st.erase(st.begin());
sum += w;
for (int e : adj[j]) {
if (!vis[e]) {
vis[e] = 1;
st.emplace(s[e], e);
}
}
}
if (res[i] == '?')
res[i] = char('0' + st.empty());
}
string ans(n, '?');
for (int i = 0; i < n; i++) {
ans[ix[i]] = res[i];
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
85 ms |
416 KB |
Output is correct |
5 |
Correct |
20 ms |
436 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
89 ms |
408 KB |
Output is correct |
8 |
Correct |
78 ms |
400 KB |
Output is correct |
9 |
Correct |
166 ms |
476 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
16 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
16168 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1062 ms |
14408 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1073 ms |
14816 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
85 ms |
416 KB |
Output is correct |
5 |
Correct |
20 ms |
436 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
89 ms |
408 KB |
Output is correct |
8 |
Correct |
78 ms |
400 KB |
Output is correct |
9 |
Correct |
166 ms |
476 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
16 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
1085 ms |
16168 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |