Submission #1279137

#TimeUsernameProblemLanguageResultExecution timeMemory
1279137friendiksStranded Far From Home (BOI22_island)C++20
0 / 100
89 ms17408 KiB
#ifndef LOCAL #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC diagnostic ignored "-Wpedantic" #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rnd(seed); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T, typename V> using table = gp_hash_table<T, V>; using i128 = __int128; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; const ll INF = 1e13; const int inf = 1e9; const int maxk = 140; const int MOD = 1e9 + 7; const double pi = acos(-1); const int P = 5167; const int L = 26; const ld EPS = 1e-7; const int W = 3; const int MBIT = 18; const int maxn = 2e5 + 7; const int B = 550; template<typename T, typename V> void fill(T &container, V value) { for (auto &c : container) c = value; } # define int ll int p[maxn]; int sz[maxn]; int curr[maxn]; int get(int v) { if (v == p[v]) return v; return p[v] = get(p[v]); } void unite(int u, int v) { u = get(u); v = get(v); if (get(u) == get(v)) return; if (sz[u] > sz[v]) swap(u, v); p[u] = v; sz[v] += sz[u]; curr[v] += curr[u]; } void solve() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { p[i] = i; sz[i] = 1; } vector<vector<int> > G(n); vector<pair<int, int> > a(n); for (int i = 0; i < n; ++i) { cin >> a[i].first; a[i].second = i; curr[i] = a[i].first; } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; u--; v--; if (a[u] > a[v]) G[u].push_back(v); else G[v].push_back(u); } sort(a.begin(), a.end()); for (int i = 0; i < n; ++i) { int u = a[i].second; for (auto v : G[u]) { if (a[i].first <= curr[get(v)]) { unite(u, v); } } } for (int i = 0; i < n; ++i) cout << (get(i) == get(a.back().second)); } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(9); int t = 1; //cin >> t; while (t--) solve(); #ifdef LOCAL cout << "\n\n\n=====================================================\nProgram worked for: "; cout << (ld) clock() / CLOCKS_PER_SEC << "s"; #endif //stress(); }
#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...