Submission #640236

#TimeUsernameProblemLanguageResultExecution timeMemory
640236devariaotaStranded Far From Home (BOI22_island)C++17
0 / 100
198 ms17124 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") typedef long long ll; // const ll mod = 1e9 + 7; const ll MAXN = 2e5 + 5; #define vi vector<int> #define vll vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define sc second #define endl '\n' #define gl ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) int n, m, u, v; vi adj[MAXN]; int par[MAXN]; ll val[MAXN]; bool vis[MAXN]; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; int fpar(int a) { return par[a] = (par[a] == a ? a : fpar(par[a])); } int main() { gl; cin >> n >> m; ll mx = 0; for (int i = 1; i <= n; i++) { cin >> val[i]; par[i] = i; pq.push({val[i], i}); mx = max(mx, val[i]); } for (int i = 1; i <= m; i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } while (!pq.empty()) { auto [va, idx] = pq.top(); // cout << ":: " << va << ' ' << idx << endl; pq.pop(); vis[idx] = 1; if (va != val[fpar(par[idx])]) continue; for (int i : adj[idx]) { if (!vis[i] and val[fpar(par[idx])] >= val[fpar(par[i])]) { vis[i] = 1; val[i] += va; par[idx] = fpar(par[i]); pq.push({val[i], i}); } } } for (int i = 1; i <= n; i++) { if (val[fpar(par[i])] >= mx) cout << 1; else cout << 0; } cout << endl; // for (int i = 1; i <= n; i++) // { // cout << par[i] << ' '; // } // cout << endl; return 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...