Submission #1098906

#TimeUsernameProblemLanguageResultExecution timeMemory
1098906crafticatStranded Far From Home (BOI22_island)C++17
0 / 100
262 ms18120 KiB
#include <bits/stdc++.h> #include <utility> using namespace std; #define F0R(i, n) for (int i= 0; i < n;i++) template<typename T> using V = vector<T>; using vi = V<int>; using vvi = V<vi>; #define pb push_back using pi = pair<int, int>; #define all(x) begin(x), end(x) #define f first #define s second V<int> initSum; struct dsu { vi par; vi siz; vi sum; dsu(int n, vi initSum) { par.resize(n, -1); siz.resize(n, 1); sum = std::move(initSum); } int get(int x) { if (par[x] == -1) return x; return get(par[x]); } void combine(int a, int b) { a = get(a), b = get(b); if (a == b) return; if (initSum[b] > initSum[a]) swap(a,b); siz[a] += siz[b]; sum[a] += sum[b]; par[b] = a; } }; //TODO CHECK CONNECTIVITY vvi genGraph(vi par) { vvi g(par.size()); F0R(i, par.size()) { if (par[i] == -1) continue; g[par[i]].pb(i); g[i].pb(par[i]); } return g; } V<bool> possible; dsu* dsu; vvi g; void dfsPos(int x, int p) { if (p == -1 || dsu->sum[x] >= initSum[p]) possible[x] = true; else return; for (auto child : g[x]) { if (child == p) continue; dfsPos(child, x); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; V<pair<int, pi>> edges; initSum.resize(n + 1); F0R(i, n) cin >> initSum[i + 1]; F0R(i, m) { int a, b; cin >> a>> b; edges.pb({max(initSum[a], initSum[b]), {a, b}}); } sort(all(edges)); dsu = new struct dsu(n + 1, initSum); for (auto [x,pa] : edges) { auto [a,b] = pa; dsu->combine(a,b); } g = genGraph(dsu->par); int root = dsu->get(1); possible.resize(n + 1); dfsPos(root, -1); F0R(i, n) { cout << possible[i + 1] << " "; } return 0; }

Compilation message (stderr)

island.cpp: In function 'vvi genGraph(vi)':
island.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define F0R(i, n) for (int i= 0; i < n;i++)
......
   50 |     F0R(i, par.size()) {
      |         ~~~~~~~~~~~~~               
island.cpp:50:5: note: in expansion of macro 'F0R'
   50 |     F0R(i, par.size()) {
      |     ^~~
#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...