func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, w, csets;   int weights[1001];   int beauties[1001];   int ranksz[1001];   int parents[1001];   bool superprnt[1001];   vector<vector<int>> setlist;   vector<int> beautysum;   vector<int> wtsum;   map<int, int> setidmap;   vector<vector<int>> dpmap;   int find_parent(int i) {     if (parents[i] == i) return i;     return parents[i] = find_parent(parents[i]);   }   void union_nodes(int a, int b) {     int prta{find_parent(a)};     int prtb{find_parent(b)};     if (prta == prtb) return;     if (ranksz[prta] > ranksz[prtb]) {       parents[prtb] = prta;       ranksz[prta] += ranksz[prtb];       superprnt[prtb] = 0;     } else {       parents[prta] = prtb;       ranksz[prtb] += ranksz[prta];       superprnt[prta] = 0;     }   }   int solvedp(int i, int wts) {     if (i == csets || wts == 0) return 0;     if (dpmap[i][wts] != -1) return dpmap[i][wts];     int ans1{-500}, ans2{-500}, ans3{-500};     if (wtsum[i] <= wts) ans1 = beautysum[i] + solvedp(i + 1, wts - wtsum[i]);     for (int j : setlist[i]) {       if (weights[j] <= wts) {         ans2 = max(ans2, beauties[j] + solvedp(i + 1, wts - weights[j]));       }     }     ans3 = solvedp(i + 1, wts);     return dpmap[i][wts] = max(max(ans1, ans2), ans3);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m, a, b;     cin >> n >> m >> w;     for (int i = 1; i <= n; ++i) {       cin >> weights[i];       parents[i] = i;       ranksz[i] = 1;       superprnt[i] = 1;     }     for (int i = 1; i <= n; ++i) {       cin >> beauties[i];     }     for (int i = 0; i < m; ++i) {       cin >> a >> b;       union_nodes(a, b);     }     int setid{0};     csets = 0;     for (int i = 1; i <= n; ++i) {       if (superprnt[i]) {         csets++;         setidmap[i] = setid++;       }     }     setlist = vector<vector<int>>(csets);     beautysum = vector<int>(csets, 0);     wtsum = vector<int>(csets, 0);     for (int i = 1; i <= n; ++i) {       int prt{find_parent(i)};       int id{setidmap[prt]};       setlist[id].push_back(i);       beautysum[id] += beauties[i];       wtsum[id] += weights[i];     }     dpmap = vector<vector<int>>(csets, vector<int>(w + 1, -1));     int ans{solvedp(0, w)};     cout << ans <<   n ;     return 0;   }   