(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1117791

#TimeUsernameProblemLanguageResultExecution timeMemory
1117791vjudge1Paprike (COI18_paprike)C++17
24 / 100
67 ms8536 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int sz = 3e5 + 5; vector<int> sira(sz); int n,k; struct DSU{ vector<int> p,comp; void init(){ p.resize(n+1); comp.resize(n+1); for(int i=1;i<=n;++i){ p[i] = i; comp[i] = sira[i]; } }; int FIND(int a){ return (p[a] == a ? a : p[a] = FIND(p[a])); } void UNI(int a,int b){ a = FIND(a); b = FIND(b); if(a == b)return; comp[a] += comp[b]; p[b] = a; } }; signed main(){ cin >> n >> k; for(int i=1;i<=n;++i){ cin >> sira[i]; } int a,b; vector<pair<int,int>> hmm(n); for(int i=0;i<n-1;++i){ cin >> a >> b; hmm[i] = {a,b}; } if(n> 15){ DSU temp; temp.init(); for(int i=0;i<hmm.size();++i){ a= temp.FIND(hmm[i].first); b = temp.FIND(hmm[i].second); if(a == b)continue; if(temp.comp[a] + temp.comp[b] > k)continue; temp.UNI(a,b); } unordered_set<int> st; for(int i=1;i<=n;++i)st.insert(temp.FIND(i)); cout << st.size() - 1; return 0; } int mink = n; for(int mask=0;mask<(1 << hmm.size());++mask){ DSU temp; temp.init(); for(int j=0;j<hmm.size();++j){ if((1 << j) & mask){ temp.UNI(hmm[j].first,hmm[j].second); } } unordered_set<int> st; bool valid = 1; for(int i=1;i<=n;++i){ if(temp.comp[temp.FIND(i)] > k){ valid = 0; break; } st.insert(temp.FIND(i)); } if(!valid)continue; a = st.size() - 1; mink = min(mink,a); } cout << mink; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:45:22: 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]
   45 |         for(int i=0;i<hmm.size();++i){
      |                     ~^~~~~~~~~~~
paprike.cpp:61:22: 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]
   61 |         for(int j=0;j<hmm.size();++j){
      |                     ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...