Submission #578182

#TimeUsernameProblemLanguageResultExecution timeMemory
578182idasStranded Far From Home (BOI22_island)C++11
100 / 100
612 ms60764 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define sz(x) ((int)((x).size())) #define le(vec) vec[vec.size()-1] #define all(x) (x).begin(), (x).end() #define TSTS int ttt; cin >> ttt; while(ttt--) solve() #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int INF=1e9, MOD=1e9+7, mod=998244353; const ll LINF=1e18; void setIO() { FAST_IO; } void setIO(string s) { FAST_IO; freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const int N=2e5+10; int n, m, c[N], par[N]; vi ad[N], ok[N]; map<int, vi> col; set<int> dif; bool can[N]; ll sm[N]; int fnd(int u) { return par[u]=par[u]==u?u:fnd(par[u]); } void mrg(int a, int b) { a=fnd(a); b=fnd(b); if(a==b) return; if(sz(ok[a])>sz(ok[b])) ok[a].swap(ok[b]); for(auto x : ok[a]) ok[b].pb(x); sm[b]+=sm[a]; par[a]=b; } int main() { setIO(); cin >> n >> m; FOR(i, 0, n) cin >> c[i], dif.insert(c[i]), col[c[i]].pb(i), par[i]=i, ok[i].pb(i), can[i]=true, sm[i]=c[i]; FOR(i, 0, m) { int a, b; cin >> a >> b; ad[a-1].pb(b-1); ad[b-1].pb(a-1); } for(auto val : dif){ for(auto i : col[val]){ for(auto x : ad[i]){ if(c[x]>c[i]) continue; x=fnd(x); if(sm[x]<c[i]){ while(sz(ok[x])){ can[ok[x].back()]=false; ok[x].pop_back(); } } mrg(i, x); } } } FOR(i, 0, n) cout << can[i]; }

Compilation message (stderr)

island.cpp: In function 'void setIO(std::string)':
island.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...