Submission #592974

#TimeUsernameProblemLanguageResultExecution timeMemory
5929741zaid1Stranded Far From Home (BOI22_island)C++17
20 / 100
282 ms62392 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' const int M = 4e5+1; #define int long long vector<int> node[M], v[M]; bitset<200005> vis; int p[M], n, cnt[M]; struct in{int a;}; bool operator<(in a, in b) {return p[a.a] > p[b.a];} bool bfs(int s) { for (int i = 1; i <= n; i++) vis[i] = 0; int sum = 0; priority_queue<in> q; vis[s] = 1; q.push({s}); while (!q.empty()) { auto [t] = q.top(); q.pop(); if (t != s && p[t] > sum) { return 0; } else sum += p[t]; for (int i:node[t]) { if (!vis[i]) { vis[i] = 1; q.push({i}); } } } return true; } void dfs(int s) { cnt[s] = p[s]; vis[s] = true; v[s].push_back(s); for (int i:node[s]) { if (!vis[i]) { dfs(i); if (cnt[i] >= p[s]) { if (v[i].size() > v[s].size()) swap(v[s], v[i]); for (int j:v[i]) v[s].push_back(j); } cnt[s] += cnt[i]; } } } signed main() { cin.tie(0)->sync_with_stdio(0); int m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; node[a].push_back(b); node[b].push_back(a); } if (n <= 2000) { for (int i = 1; i <= n; i++) sort(node[i].begin(), node[i].end(),[](int a, int b) {return p[a] < p[b];}); for (int i = 1; i <= n; i++) cout << bfs(i); cout << endl; } else { dfs(1); bitset<200005> bt; for (int i:v[1]) bt[i] = 1; for (int i = 1; i <= n; i++) cout << bt[i]; cout << endl; } return 0; } /* 4 3 4 2 2 1 1 2 3 2 4 1 */

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:68:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   68 |         for (int i = 1; i <= n; i++) cout << bfs(i); cout << endl;
      |         ^~~
island.cpp:68:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   68 |         for (int i = 1; i <= n; i++) cout << bfs(i); cout << endl;
      |                                                      ^~~~
island.cpp:73:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   73 |         for (int i = 1; i <= n; i++) cout << bt[i]; cout << endl;
      |         ^~~
island.cpp:73:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |         for (int i = 1; i <= n; i++) cout << bt[i]; cout << endl;
      |                                                     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...