Submission #1030916

#TimeUsernameProblemLanguageResultExecution timeMemory
1030916UnforgettableplSecurity Guard (JOI23_guard)C++17
50 / 100
116 ms21280 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct UFDS{ vector<int> p,siz,mini; UFDS(int n,vector<int> arr):p(n+1),siz(n+1,1),mini(n+1){ iota(p.begin(),p.end(),0); mini=arr; } int findRoot(int x){ return p[x]==x ? x : p[x]=findRoot(p[x]); } int unite(int a,int b){ a = findRoot(a); b = findRoot(b); if(a==b)return -1; if(siz[b]>siz[a])swap(a,b); int ans = mini[a]+mini[b]; int maxi = max(mini[a],mini[b]); mini[a]=min(mini[a],mini[b]); siz[a]+=siz[b]; p[b]=a; return ans; } }; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,m,q; cin >> n >> m >> q; vector<int> arr(n+1); for(int i=1;i<=n;i++)cin>>arr[i]; vector<tuple<int,int,int>> edges; for(int i=1;i<=m;i++){ int a,b; cin >> a >> b; edges.emplace_back(arr[a]+arr[b],a,b); } sort(edges.begin(),edges.end()); int baseans = (*max_element(arr.begin(),arr.end())); for(int i=1;i<=n;i++){ baseans-=arr[i]; } UFDS dsu(n,arr); vector<int> ans(n); int minima = *min_element(arr.begin()+1,arr.end()); int iter = 1; priority_queue<int> qu; for(int i=0;i<m;i++){ auto [cost,a,b] = edges[i]; auto curr = dsu.unite(a,b); if(curr==-1)continue; baseans+=cost; qu.emplace(curr-cost); } for(int i=0;i<=q;i++){ cout << baseans << '\n'; if(!qu.empty()){ baseans+=qu.top(); qu.pop(); } } }

Compilation message (stderr)

guard.cpp: In member function 'long long int UFDS::unite(long long int, long long int)':
guard.cpp:21:7: warning: unused variable 'maxi' [-Wunused-variable]
   21 |   int maxi = max(mini[a],mini[b]);
      |       ^~~~
guard.cpp: In function 'int32_t main()':
guard.cpp:50:6: warning: unused variable 'minima' [-Wunused-variable]
   50 |  int minima = *min_element(arr.begin()+1,arr.end());
      |      ^~~~~~
guard.cpp:51:6: warning: unused variable 'iter' [-Wunused-variable]
   51 |  int iter = 1;
      |      ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...