Submission #1002485

#TimeUsernameProblemLanguageResultExecution timeMemory
1002485AndreyStranded Far From Home (BOI22_island)C++14
100 / 100
144 ms45040 KiB
#include<bits/stdc++.h> using namespace std; vector<long long> haha[200001]; vector<long long> dsu(200001); vector<long long> tree[200001]; vector<long long> st(200001); vector<long long> wow(200001); vector<bool> ans(200001); long long calc(long long a) { long long c = a,e = a; while(dsu[c] != c) { c = dsu[c]; } while(e != dsu[e]) { long long d = dsu[e]; dsu[e] = c; e = d; } return c; } void dfs(long long a) { st[a] = wow[a]; for(long long v: tree[a]) { dfs(v); st[a]+=st[v]; } } void dude(long long a) { ans[a] = true; for(long long v: tree[a]) { if(st[v] >= wow[a]) { dude(v); } } } int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); long long n,m,a,b; cin >> n >> m; vector<pair<long long,long long>> wut(0); for(long long i = 1; i <= n; i++) { cin >> wow[i]; dsu[i] = i; wut.push_back({wow[i],i}); } sort(wut.begin(),wut.end()); vector<int> pos(n+1); for(int i = 0; i < n; i++) { pos[wut[i].second] = i; } for(long long i = 0; i < m; i++) { cin >> a >> b; if(pos[a] > pos[b]) { haha[a].push_back(b); } else { haha[b].push_back(a); } } for(long long i = 0; i < wut.size(); i++) { long long a = wut[i].second; for(long long v: haha[a]) { if(calc(v) != calc(a)) { tree[a].push_back(calc(v)); dsu[calc(v)] = a; } } } dfs(wut[n-1].second); dude(wut[n-1].second); for(long long i = 1; i <= n; i++) { cout << ans[i]; } cout << endl; return 0; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:68:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(long long i = 0; i < wut.size(); 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...