Submission #849868

#TimeUsernameProblemLanguageResultExecution timeMemory
84986812345678Stranded Far From Home (BOI22_island)C++17
10 / 100
386 ms756 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e3+10; #define ll long long int n, m, u, v, s[nx]; vector<int> d[nx]; bool vs[nx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; for (int i=1; i<=n; i++) cin>>s[i]; for (int i=1; i<=m; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u); for (int i=1; i<=n; i++) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; ll sz=0, cnt=0; for (int j=1; j<=n; j++) vs[j]=0; pq.push({0, i}); while (!pq.empty()) { int x=pq.top().first, y=pq.top().second; pq.pop(); if (sz<x||vs[y]) continue; vs[y]=1; cnt++; sz+=s[y]; for (auto nw:d[y]) { //cout<<i<<' '<<sz<<' '<<nw<<' '<<s[nw]<<'\n'; pq.push({s[nw], nw}); } } if (cnt==n) cout<<1; else cout<<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...