func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int W = 1005;   const long long inf = 1e18;   struct dsu {     vector<int> pr;     vector<int> weights;     vector<long long> beauties;     set<int> roots;     dsu(int _n) {       pr.resize(_n + 5);       weights.resize(_n + 5);       beauties.resize(_n + 5);       iota((pr).begin(), (pr).end(), 0);       for (int u = (1); u <= ((_n)); u += (+1)) {         roots.insert(u);       }     }     int find(int u) { return pr[u] == u ? u : pr[u] = find(pr[u]); }     bool unite(int u, int v) {       u = find(u);       v = find(v);       if (u != v) {         pr[u] = v;         beauties[v] += beauties[u];         weights[v] += weights[u];         roots.erase(u);         return true;       }       return false;     }   };   set<int> who[W];   long long dp[W];   int weights[N];   long long beauties[N];   bool done[W];   int n, m, max_w;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);     cin >> n >> m >> max_w;     dsu dg(n);     for (int u = (1); u <= ((n)); u += (+1)) {       int w;       cin >> w;       dg.weights[u] = weights[u] = w;     }     for (int u = (1); u <= ((n)); u += (+1)) {       long long b;       cin >> b;       dg.beauties[u] = beauties[u] = b;     }     for (int i = (0); i <= ((m)-1); i += (+1)) {       int u, v;       cin >> u >> v;       dg.unite(u, v);     }     done[0] = true;     for (int u : dg.roots) {       for (int w = (max_w); w >= (0); w += (-1)) {         if (w - dg.weights[u] < 0) {           break;         }         int ru = dg.find(u);         if (dp[w - dg.weights[u]] + dg.beauties[u] > dp[w] &&             !who[w - dg.weights[ru]].count(ru) && done[w - dg.weights[u]]) {           done[w] = true;           dp[w] = dp[w - dg.weights[u]] + dg.beauties[u];           who[w] = who[w - dg.weights[u]];           who[w].insert(ru);         }       }     }     for (int u = (1); u <= ((n)); u += (+1)) {       for (int w = (max_w); w >= (0); w += (-1)) {         if (w - weights[u] < 0) {           break;         }         int ru = dg.find(u);         if (dp[w - weights[u]] + beauties[u] > dp[w] &&             !who[w - weights[u]].count(ru) && done[w - weights[u]]) {           done[w] = true;           dp[w] = dp[w - weights[u]] + beauties[u];           who[w] = who[w - weights[u]];           who[w].insert(ru);         }       }     }     cout << *max_element(dp, dp + max_w + 1) <<   n ;     return 0;   }   