Submission #714615

#TimeUsernameProblemLanguageResultExecution timeMemory
714615TheSahibStranded Far From Home (BOI22_island)C++14
10 / 100
343 ms12260 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int MAX = 2e5 + 5; int n, m; int arr[MAX]; vector<int> g[MAX]; bool visited[MAX]; bool bfs(int start){ fill(visited, visited + n + 1, 0); ll cnt = 0; set<pii> q; q.insert({arr[start], start}); while(!q.empty()){ int node = q.begin()->second; int c = q.begin()->first; q.erase(q.begin()); visited[node] = true; if(cnt >= c || node == start){ cnt += c; for(int to:g[node]){ if(visited[to]) continue; q.insert({arr[to], to}); } } else{ return false; } } return true; } int main(){ cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a].emplace_back(b); g[b].emplace_back(a); } if(n > 2000 || m > 2000){ cout << 1; for (int i = 2; i <= n; i++) { cout << (arr[i] == arr[1]); } return 0; } for (int i = 1; i <= n; i++) { cout << bfs(i); } }
#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...