# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
723025 | 2023-04-13T07:36:26 Z | Erkinoff_Mohammed | Stranded Far From Home (BOI22_island) | C++14 | 0 ms | 0 KB |
#include "bits/stdc++.h" #include "communication.h" using namespace std; #define INF 2000000000 #define INFLL 3000000000000000000LL #define ll long long int main() { cin.tie(0)->sync_with_stdio(0); int n,m; cin>>n>>m; if(n<=2000&&m<=2000){ long long siz[n+1]; for(int i=1;i<=n;i++)cin>>siz[i]; vector<int>adj[n+1]; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } for(int i=1;i<=n;i++){ bool vis[n+1]; for(int i=0;i<=n;i++)vis[i]=0; priority_queue<pair<int,int>>q; long long cur=siz[i]; bool b=1; q.push({0,i}); while(!q.empty()){ auto u=q.top();q.pop(); int j=u.second; int si=-u.first; if(si>cur){ b=0; break; } vis[j]=1; cur+=si; for(int v:adj[j]){ if(!vis[v])q.push({-siz[v],v}); } } cout<<b; } } }