#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);
}
}
}
cout << res << '\n';
if (res[i] == '?')
res[i] = char('0' + st.empty());
}
string ans(n, '?');
for (int i = 0; i < n; i++) {
ans[jx[i]] = res[i];
}
cout << ans << '\n';
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
30 | for (int i : ix) cout << i << ' ';cout << endl;
| ^~~
island.cpp:30:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
30 | for (int i : ix) cout << i << ' ';cout << endl;
| ^~~~
island.cpp:31:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
31 | for (int i : jx) cout << i << ' ';cout << endl;
| ^~~
island.cpp:31:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
31 | for (int i : jx) cout << i << ' ';cout << endl;
| ^~~~
island.cpp:32:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
32 | for (int i : s) cout << i << ' ';cout << endl;
| ^~~
island.cpp:32:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
32 | for (int i : s) cout << i << ' ';cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |