Submission #1305579

#TimeUsernameProblemLanguageResultExecution timeMemory
1305579xanlar2009Stranded Far From Home (BOI22_island)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define run ios_base::sync_with_stdio(false);cin.tie(0); #define ln length() #define ll long long #define pll pair<ll, ll> #define ull unsigned ll #define ld long double #define endl "\n" #define pb push_back #define fi first #define se second #define pi acos(-1) #define N 2007 #define INF 10000000000000000 #define minimum -9000000000000000000 #define maximum -minimum #define mod 998244353 using namespace std; //using namespace __gnu_pbds; //template <class t> //using ordered_set=tree<t, null_type,less<t>, rb_tree_tag,tree_order_statistics_node_update>; //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll gcd(ll a, ll b) { if(b==0) return a; return gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } bool isprime(ll n) { if(n==1) return 1; for(ll i=2; i*i<=n; i++) { if(n%i==0) return 0; } return 1; } ll binpow(ll a, ll b) { a%=mod; ll res=1; while(b>0) { if(b%2==1) res=(res*a)%mod; a=(a*a)%mod; b/=2; } return res; } ll n, m; ll a[N]; vector<ll>v[N]; bool used[N]; priority_queue<pll, vector<pll>, greater<pll>>pq; void dijk(ll node) { ll tot=a[node]; for(ll i:v[node]) { pq.push({a[i], i}); } while(!pq.empty()) { ll t=pq.top().second; ll d=pq.top().first; pq.pop(); if(d>tot) { return; } used[t]=1; tot+=d; for(ll i:v[t]) { if(!used[i]) { pq.push({a[i], i}); } } } } int main() { run; cin>>n>>m; for(ll i=1; i<=n; i++) { cin>>a[i]; } for(ll i=1; i<=m; i++) { ll x, y; cin>>x>>y; v[x].pb(y); v[y].pb(x); } for(ll i=1; i<=n; i++) { for(ll j=1; j<=n; j++) { used[j]=0; } dijk(i); bool bul=1; for(ll j=1; j<=n; j++) { if(!used[j]) bul=0; } if(bul) cout<<1; else cout<<0; } } /* 6 1 3 8 1 2 1 5 4 */ // By Xanlar
#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...