제출 #1155487

#제출 시각아이디문제언어결과실행 시간메모리
1155487CrabCNHStranded Far From Home (BOI22_island)C++20
100 / 100
82 ms13548 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) using namespace std; template <class T> void mini (T &t, T f) {if (t > f) t = f;} template <class T> void maxi (T &t, T f) {if (t < f) t = f;} const int maxN = 2e5 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; int n, m; int a[maxN], par[maxN], mxSz[maxN]; bool aval[maxN]; vector <tuple <int, int, int>> all; void init () { for (int i = 1; i <= n; i ++) { par[i] = i; mxSz[i] = a[i]; aval[i] = false; } } int getRoot (int u) { if (par[u] == u) { return u; } int p = getRoot (par[u]); aval[u] |= aval[par[u]]; return (par[u] = p); } void merge (int u, int v) { u = getRoot (u); v = getRoot (v); if (u == v) { return; } if (mxSz[v] < a[u]) { aval[v] = true; } par[v] = u; mxSz[u] += mxSz[v]; } void solve () { cin >> n >> m; for (int i = 1; i <= n; i ++) { cin >> a[i]; } init (); for (int i = 1; i <= m; i ++) { int u, v; cin >> u >> v; if (a[u] < a[v]) { swap (u, v); } all.push_back ({a[u], u, v}); } sort (all.begin (), all.end ()); for (auto [_, u, v] : all) { merge (u, v); } for (int i = 1; i <= n; i ++) { getRoot (i); cout << (!aval[i] ? 1 : 0); } } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

island.cpp: In function 'int main()':
island.cpp:83:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:84:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         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...