Submission #937429

#TimeUsernameProblemLanguageResultExecution timeMemory
937429weakweakweakStranded Far From Home (BOI22_island)C++14
100 / 100
175 ms43680 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n, m, s[201000], fa[201000], sz[201000], vis[201000] = {0}, ans[201000], dead[201000] = {0}; ll w[201000]; vector <int> e[201000], ne[201000]; int find (int x) {return fa[x] == x? x : fa[x] = find(fa[x]);} void dfs(int i) { ans[i] = !dead[i]; for (int j : ne[i]) { dead[j] |= dead[i]; dfs(j); } return;} int main () { //輸入、建圖 ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i]; fa[i] = i, w[i] = s[i], sz[i] = 1; } for (int i = 0, x, y; i < m; i++) { cin >> x >> y; e[x].push_back(y);e[y].push_back(x); } //做事 vector<int> p; for (int i = 1; i <= n; i++) p.push_back(i); sort(p.begin(), p.end(), [&s](int & a, int & b){return s[a] < s[b];}); for (int ii = 0; ii < n; ii++) { int i = p[ii]; for (int j : e[i]) { if (!vis[j] or i == find(j)) continue; if (w[find(j)] < s[i]) dead[find(j)] = 1; ne[i].push_back(find(j)); w[i] += w[find(j)]; fa[find(j)] = i; } vis[i] = 1; } //從根往下跑 int rt = find(1); dfs(rt); //輸出 for (int i = 1; i <= n; i++) cout << ans[i]; cout << '\n'; return 0;}

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:35:32: warning: capture of variable 's' with non-automatic storage duration
   35 |     sort(p.begin(), p.end(), [&s](int & a, int & b){return s[a] < s[b];});
      |                                ^
island.cpp:5:11: note: 'int s [201000]' declared here
    5 | int n, m, s[201000], fa[201000], sz[201000], vis[201000] = {0}, ans[201000], dead[201000] = {0};
      |           ^
#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...