Submission #1101685

#TimeUsernameProblemLanguageResultExecution timeMemory
1101685pubin06Stranded Far From Home (BOI22_island)C++14
10 / 100
13 ms6320 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define sz(v) (int)(v).size() using namespace std; const int MXn = 100005; const long long oo = 1e18; const int MOD = 1e9 + 7; int n, m, a[MXn], s[MXn], par[MXn]; bool cant[MXn]; int find_par(int u) { if (u == par[u]) return u; int r = find_par(par[u]); cant[u] |= cant[par[u]]; return par[u] = r; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define TASK "" if (ifstream(TASK".INP")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i], s[i] = a[i]; iota(par + 1, par + 1 + n, 1); vector<array<int, 3>> es; for (int i = 1, u, v; i <= m; i++) { cin >> u >> v; if (a[u] < a[v]) swap(u, v); es.push_back({a[u], u, v}); } sort(begin(es), end(es)); for (auto e: es) { int u = e[1], v = e[2]; u = find_par(u), v = find_par(v); if (u ^ v) { cant[v] = s[v] < a[u]; s[u] += s[v]; par[v] = u; } } for (int i = 1; i <= n; i++) { find_par(i); cout << (cant[i] ? 0 : 1); } return 0; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:26:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |      freopen(TASK".INP", "r", stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:27:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |      freopen(TASK".OUT", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...