#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

int n,m,w;
int a[maxn],b[maxn];
int dp[maxn];

int ct[maxn];
int par[maxn],rk[maxn];

void init(){
    REP(i,1,n){
        par[i]=i;
        rk[i]=0;
    }
}

int Find(int x){
    return (par[x]==x)?x:par[x]=Find(par[x]);
}

void Union(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y) return;
    if(rk[x]<rk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rk[x]==rk[y]) rk[x]++;
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        init();
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            if(Find(u)!=Find(v))
                Union(u,v);
        }
        CLR(dp);
        REP(i,1,n){
            if(par[i]==i){
                int sz=0;
                REP(j,1,n){
                    if(Find(j)==i){
                       ct[sz++]=j;
                    }
                }
                RREP(j,w,0){
                    int sma=0,smb=0;
                    rep(k,0,sz){
                        int v=ct[k];
                        sma+=a[v];
                        smb+=b[v];
                        if(j-a[v]>=0){
                            dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                        }
                    }
                    if(j-sma>=0){
                       dp[j]=max(dp[j],dp[j-sma]+smb);
                    }
                }
            }
        }
        _pt(dp[w]);_pn;
    }
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

int n,m,w;
int a[maxn],b[maxn],idx;
int dp[maxn];

vector<int>ct[maxn];
int par[maxn],rk[maxn];

void init(){
    REP(i,1,n){
        par[i]=i;
        rk[i]=0;
    }
}

int Find(int x){
    return (par[x]==x)?x:par[x]=Find(par[x]);
}

void Union(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y) return;
    if(rk[x]<rk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rk[x]==rk[y]) rk[x]++;
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        init();
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            Union(u,v);
        }
        idx=0;
        REP(i,1,n){
            ct[par[i]].pb(i);
        }
        CLR(dp);
        REP(i,1,n){
            if(ct[i].size()>0){
                RREP(j,w,0){
                int sma=0,smb=0;
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    sma+=a[v];
                    smb+=b[v];
                    if(j-a[v]>=0){
                        dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                    }
                }
                if(j-sma>=0){
                   dp[j]=max(dp[j],dp[j-sma]+smb);
                }
                }
            }
        }
        _pt(dp[w]);_pn;
        REP(i,1,n){
            ct[i].clear();
        }
    }

}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

vector<int>G[maxn];

int n,m,w;
int a[maxn],b[maxn],vis[maxn],idx;
int dp[maxn];

vector<int>ct[maxn];

void dfs(int u,int rt){
    vis[u]=1;
    ct[idx].pb(u);
    rep(i,0,G[u].size()){
        int v=G[u][i];
        if(v==rt) continue;
        dfs(v,u);
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            G[u].pb(v);
            G[v].pb(u);
        }
        idx=0;
        CLR(vis);
        REP(i,1,n){
            if(!vis[i]){
                idx++;
                dfs(i,i);
            }
        }
        CLR(dp);
        REP(i,1,idx){
            RREP(j,w,0){
                int sma=0,smb=0;
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    sma+=a[v];
                    smb+=b[v];
                    if(j-a[v]>=0){
                        dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                    }
                }
                if(j-sma>=0){
                   dp[j]=max(dp[j],dp[j-sma]+smb);
                }
            }
        }
        _pt(dp[w]);_pn;
        REP(i,1,n){
            G[i].clear();
        }

        REP(i,1,idx) ct[i].clear();
    }

}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

vector<int>G[maxn];

int n,m,w;
int a[maxn],b[maxn],vis[maxn],idx;
int sma[maxn],smb[maxn];
int dp[maxn][maxn];

vector<int>ct[maxn];

void dfs(int u,int rt){
    vis[u]=1;
    sma[idx]+=a[u];
    smb[idx]+=b[u];
    ct[idx].pb(u);
    rep(i,0,G[u].size()){
        int v=G[u][i];
        if(v==rt) continue;
        dfs(v,u);
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            G[u].pb(v);
            G[v].pb(u);
        }
        idx=0;
        CLR(vis);
        REP(i,1,n){
            if(!vis[i]){
                idx++;
                dfs(i,i);
            }
        }
        CLR(dp);
        REP(i,1,idx){
            REP(j,0,w){
                dp[i][j]=dp[i-1][j];
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    if(j-a[v]>=0){
                        dp[i][j]=max(dp[i][j],dp[i-1][j-a[v]]+b[v]);
                    }
                }
                if(j-sma[i]>=0){
                   dp[i][j]=max(dp[i][j],dp[i-1][j-sma[i]]+smb[i]);
                }
            }
        }
        _pt(dp[idx][w]);_pn;
        REP(i,1,n){
            G[i].clear();
            ct[i].clear();
        }
    }

}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

vector<int>G[maxn];

int n,m,w;
int a[maxn],b[maxn],vis[maxn],idx;
int sma[maxn],smb[maxn];
int dp[maxn];

vector<int>ct[maxn];

void dfs(int u,int rt){
    vis[u]=1;
    sma[idx]+=a[u];
    smb[idx]+=b[u];
    ct[idx].pb(u);
    rep(i,0,G[u].size()){
        int v=G[u][i];
        if(v==rt) continue;
        dfs(v,u);
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            G[u].pb(v);
            G[v].pb(u);
        }
        idx=0;
        CLR(vis);
        REP(i,1,n){
            if(!vis[i]){
                idx++;
                dfs(i,i);
            }
        }
        CLR(dp);
        REP(i,1,idx){
            RREP(j,w,0){
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    if(j-a[v]>=0){
                        dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                    }
                }
                if(j-sma[i]>=0){
                   dp[j]=max(dp[j],dp[j-sma[i]]+smb[i]);
                }
            }
        }
        _pt(dp[w]);_pn;
        REP(i,1,n){
            G[i].clear();
            ct[i].clear();
        }
    }

}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

int n,m,w;
int a[maxn],b[maxn],idx;
int dp[maxn];

vector<int>ct[maxn];
int par[maxn],rk[maxn];

void init(){
    REP(i,1,n){
        par[i]=i;
        rk[i]=0;
    }
}

int Find(int x){
    return (par[x]==x)?x:par[x]=Find(par[x]);
}

void Union(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y) return;
    if(rk[x]<rk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rk[x]==rk[y]) rk[x]++;
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        init();
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            if(Find(u)!=Find(v))
                Union(u,v);
        }
        idx=0;
        REP(i,1,n){
            if(Find(i)!=Find(par[i])){
                Union(i,par[i]);
            }
            //printf("%d ",par[i]);
        }
        //printf("\n");
        REP(i,1,n){
            ct[par[i]].pb(i);
        }
        CLR(dp);
        REP(i,1,n){
            if(ct[i].size()>0){
                RREP(j,w,0){
                    int sma=0,smb=0;
                    rep(k,0,ct[i].size()){
                        int v=ct[i][k];
                        sma+=a[v];
                        smb+=b[v];
                        if(j-a[v]>=0){
                            dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                        }
                    }
                    if(j-sma>=0){
                       dp[j]=max(dp[j],dp[j-sma]+smb);
                    }
                }
            }
        }
        _pt(dp[w]);_pn;
        REP(i,1,n){
            ct[i].clear();
        }
    }
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

vector<int>G[maxn];

int n,m,w;
int a[maxn],b[maxn],vis[maxn],idx;
int dp[maxn];

vector<int>ct[maxn];

void dfs(int u,int rt){
    vis[u]=1;
    ct[idx].pb(u);
    rep(i,0,G[u].size()){
        int v=G[u][i];
        if(v==rt) continue;
        dfs(v,u);
    }
}

int main(){

        scanf("%d%d%d",&n,&m,&w);
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            G[u].pb(v);
            G[v].pb(u);
        }
        idx=0;
        CLR(vis);
        REP(i,1,n){
            if(!vis[i]){
                idx++;
                dfs(i,i);
            }
        }
        CLR(dp);
        REP(i,1,idx){
            RREP(j,w,0){
                int sma=0,smb=0;
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    sma+=a[v];
                    smb+=b[v];
                    if(j-a[v]>=0){
                        dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                    }
                }
                if(j-sma>=0){
                   dp[j]=max(dp[j],dp[j-sma]+smb);
                }
            }
        }
        _pt(dp[w]);_pn;

}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define CLR(x) memset(x,0,sizeof(x))
#define __CLR(x) memset(x,-1,sizeof(x))
#define REP(i,l,r) for(int i=l;i<=r;i++)
#define rep(i,l,r) for(int i=l;i<r;i++)
#define RREP(i,l,r) for(int i=l;i>=r;i--)
#define rrep(i,l,r) for(int i=l;i>r;i--)
#define _s(x) scanf("%d",&x)
#define _sc(x) scanf("%c",&x)
#define _ss(x) scanf(" %s",x)
#define _sl(x) scanf("%I64d",&x)
#define _sd(x) scanf("%lf",&x)
#define _pt(x) printf("%d",x)
#define _ps(x) printf("%s",x)
#define _pc(x) printf("%c",x)
#define _pd(x) printf("%f",x);
#define _pl(x) printf("%I64d",x)
#define _pn printf("\n");
#define _p printf(" ");
#define gch getchar()
#define debug(x) printf("%d\n",x)
#define pb push_back
#define ll long long
#define mp make_pair

using namespace std;

const int maxn=1000+10;

vector<int>G[maxn];

int n,m,w;
int a[maxn],b[maxn],vis[maxn],idx;
int dp[maxn];

vector<int>ct[maxn];

void dfs(int u,int rt){
    vis[u]=1;
    ct[idx].pb(u);
    rep(i,0,G[u].size()){
        int v=G[u][i];
        if(v==rt) continue;
        dfs(v,u);
    }
}

int main(){

    while(~scanf("%d%d%d",&n,&m,&w)){
        REP(i,1,n) _s(a[i]);
        REP(i,1,n) _s(b[i]);
        REP(i,1,m){
            int u,v;
            _s(u);_s(v);
            G[u].pb(v);
            G[v].pb(u);
        }
        idx=0;
        CLR(vis);
        REP(i,1,n){
            if(!vis[i]){
                idx++;
                dfs(i,i);
            }
        }
        CLR(dp);
        REP(i,1,idx){
            RREP(j,w,0){
                int sma=0,smb=0;
                rep(k,0,ct[i].size()){
                    int v=ct[i][k];
                    sma+=a[v];
                    smb+=b[v];
                    if(j-a[v]>=0){
                        dp[j]=max(dp[j],dp[j-a[v]]+b[v]);
                    }
                }
                if(j-sma>=0){
                   dp[j]=max(dp[j],dp[j-sma]+smb);
                }
            }
        }
        _pt(dp[w]);_pn;
        REP(i,1,n){
            G[i].clear();
        }
        REP(i,1,idx) ct[i].clear();
    }

}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(x) (x).begin(),(x).end()
#define gcd(a,b) __gcd(a,b)
#define lcm(x,y) (abs(x)/gcd(x,y))*abs(y)

const double eps=1e-10;
const double pi=acos(-1);

const long long N=1999;
const long long mod=1e9+7;

#define filename "file"

    int n, m, w;
int p[1010];
int tw[1010], tb[1010];
int WFGH(int x){

	if(p[x] == x)
        return x;
    return p[x] = WFGH(p[x]);
}

int W[1010], B[1010];
int d[2][1010];

inline void PL()
{

	scanf("%d%d%d", &n, &m, &w);
	for(int i=1;i<=n;i++)scanf("%d", W+i);
	for(int i=1;i<=n;i++)scanf("%d", B+i);
	for(int i=1;i<=n;i++){
		p[i] = i;
		tw[i] = W[i]; tb[i] = B[i];
	}

}

inline void G()

{

    	for(int i=0; i<m; i++){
            int x,y;
            cin>>x>>y;
		x = WFGH(x), y = WFGH(y);
		p[x] = y;
		tb[y] += tb[x]; tw[y] += tw[x];
	}

}

int main()
{
    #ifdef TXT
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
    #endif

    #ifdef NAME
        freopen (filename".in", "r", stdin);
        freopen (filename".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

PL();

    G();

	int a = 1;
	for(int i=1;i<=n;i++){
		if(WFGH(i) == i){
			for(int j=0;j<=w;j++)d[a][j] = d[a^1][j];
			for(int j=tw[i];j<=w;j++){
				d[a][j] = max(d[a][j], d[a^1][j - tw[i]] + tb[i]);
			}
			for(int j=1;j<=n;j++)if(WFGH(j) == i){
				for(int k=W[j];k<=w;k++){
					d[a][k] = max(d[a][k], d[a^1][k - W[j]] + B[j]);
				}
			}
			a ^= 1;
		}
	}
	cout<<d[a^1][w]<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector <int> v[1010];
vector <int> g[1010];
bool vi[1010];

void dfs(int x, int root) {
	v[root].push_back(x);
	vi[x] = true;
	for(auto i : g[x]) {
		if(vi[i] == true) continue;
		dfs(i, root);
	}
}
typedef long long Long;

int N;
int w[1010];
int b[1010];
const Long inf = 1e15;
int des;

Long fn[1005][1005];

Long dp (int x, int weight) {
	if(weight > des) return -inf;
	if(x == N + 1) return 0;

	int sum = 0;
	int gum = 0;
	Long & ans = fn[x][weight];
	if(ans != -1) return ans;

	ans = dp(x + 1, weight);
	for(auto i : v[x]) {
		sum += w[i];
		gum += b[i];
		ans = max(ans, dp(x + 1, weight + w[i]) + b[i]);
	}
	ans = max(ans, dp(x + 1, weight + sum) + gum);
	return ans;
}

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d %d", &n, &m, &des);
	for(int i = 1; i <= n; i++) {
		scanf("%d", w + i);
	}
	for(int i = 1; i <= n; i++) {
		scanf("%d", b + i);
	}
	for(int i = 0; i < m; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		g[p].push_back(q);
		g[q].push_back(p);
	}

	for(int i = 1; i <= n; i++) {
		if(vi[i] == false) {
			dfs(i, ++N);
		}
	}
	memset(fn, -1, sizeof fn);
	printf("%I64d\n", dp(1, 0));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(x) (x).begin(),(x).end()
#define gcd(a,b) __gcd(a,b)
#define lcm(x,y) (abs(x)/gcd(x,y))*abs(y)

const double eps=1e-10;
const double pi=acos(-1);

const long long N=1999;
const long long mod=1e9+7;

#define filename "file"

    int n, m, w;
int p[1010];
int tw[1010], tb[1010];
int Find(int x){
	return p[x] == x ? x : p[x] = Find(p[x]);
}

int W[1010], B[1010];
int d[2][1010];

int main()
{
    #ifdef TXT
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
    #endif

    #ifdef NAME
        freopen (filename".in", "r", stdin);
        freopen (filename".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
	scanf("%d%d%d", &n, &m, &w);
	for(int i=1;i<=n;i++)scanf("%d", W+i);
	for(int i=1;i<=n;i++)scanf("%d", B+i);
	for(int i=1;i<=n;i++){
		p[i] = i;
		tw[i] = W[i]; tb[i] = B[i];
	}
	for(i=0; i<m; i++){
            int x,y;
            cin>>x>>y;
		x = Find(x), y = Find(y);
		p[x] = y;
		tb[y] += tb[x]; tw[y] += tw[x];
	}
	int a = 1;
	for(int i=1;i<=n;i++){
		if(Find(i) == i){
			for(int j=0;j<=w;j++)d[a][j] = d[a^1][j];
			for(int j=tw[i];j<=w;j++){
				d[a][j] = max(d[a][j], d[a^1][j - tw[i]] + tb[i]);
			}
			for(int j=1;j<=n;j++)if(Find(j) == i){
				for(int k=W[j];k<=w;k++){
					d[a][k] = max(d[a][k], d[a^1][k - W[j]] + B[j]);
				}
			}
			a ^= 1;
		}
	}
	cout<<d[a^1][w]<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(x) (x).begin(),(x).end()
#define gcd(a,b) __gcd(a,b)
#define lcm(x,y) (abs(x)/gcd(x,y))*abs(y)

const double eps=1e-10;
const double pi=acos(-1);

const long long N=1999;
const long long mod=1e9+7;

#define filename "file"

    int n, m, w;
int p[1010];
int tw[1010], tb[1010];
int Find(int x){
	return p[x] == x ? x : p[x] = Find(p[x]);
}

int W[1010], B[1010];
int d[2][1010];

int main()
{
    #ifdef TXT
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
    #endif

    #ifdef NAME
        freopen (filename".in", "r", stdin);
        freopen (filename".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
	scanf("%d%d%d", &n, &m, &w);
	for(int i=1;i<=n;i++)scanf("%d", W+i);
	for(int i=1;i<=n;i++)scanf("%d", B+i);
	for(int i=1;i<=n;i++){
		p[i] = i;
		tw[i] = W[i]; tb[i] = B[i];
	}
	for(int i=0; i<m; i++){
            int x,y;
            cin>>x>>y;
		x = Find(x), y = Find(y);
		p[x] = y;
		tb[y] += tb[x]; tw[y] += tw[x];
	}
	int a = 1;
	for(int i=1;i<=n;i++){
		if(Find(i) == i){
			for(int j=0;j<=w;j++)d[a][j] = d[a^1][j];
			for(int j=tw[i];j<=w;j++){
				d[a][j] = max(d[a][j], d[a^1][j - tw[i]] + tb[i]);
			}
			for(int j=1;j<=n;j++)if(Find(j) == i){
				for(int k=W[j];k<=w;k++){
					d[a][k] = max(d[a][k], d[a^1][k - W[j]] + B[j]);
				}
			}
			a ^= 1;
		}
	}
	cout<<d[a^1][w]<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(x) (x).begin(),(x).end()
#define gcd(a,b) __gcd(a,b)
#define lcm(x,y) (abs(x)/gcd(x,y))*abs(y)

const double eps=1e-10;
const double pi=acos(-1);

const long long N=1999;
const long long mod=1e9+7;

#define filename "file"

    int n, m, w;
int p[1010];
int tw[1010];
int tb[1010];

int PLWEF(int x){

	if(p[x] == x)
        return x;
    return p[x] = PLWEF(p[x]);
}

int W[1010], B[1010];
int d[2][1010];

inline void PL()
{

	scanf("%d%d%d", &n, &m, &w);
	for(int i=1;i<=n;i++)scanf("%d", W+i);

	for(int i=1;i<=n;i++)scanf("%d", B+i);

	for(int i=1;i<=n;i++){

		p[i] = i;

		tw[i] = W[i];

		 tb[i] = B[i];

	}

}

inline void G()

{

    	for(int i=0; i<m; i++){
            int x,y;
            cin>>x>>y;
		x = PLWEF(x), y = PLWEF(y);
		p[x] = y;
		tb[y] += tb[x]; tw[y] += tw[x];
	}

}

int main()
{
    #ifdef TXT
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
    #endif

    #ifdef NAME
        freopen (filename".in", "r", stdin);
        freopen (filename".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

PL();

    G();

	int a = 1;
	for(int i=1;i<=n;i++){
		if(PLWEF(i) == i){
			for(int j=0;j<=w;j++)d[a][j] = d[a^1][j];
			for(int j=tw[i];j<=w;j++){

            int L= max(d[a][j], d[a^1][j - tw[i]] + tb[i]);
				d[a][j] = L;

			}
			for(int j=1;j<=n;j++)if(PLWEF(j) == i){
				for(int k=W[j];k<=w;k++){

                        int PLI=max(d[a][k], d[a^1][k - W[j]] + B[j]);

					d[a][k] = PLI;
				}
			}
			a ^= 1;
		}
	}
	cout<<d[a^1][w]<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
vector<int>ss[maxn];
typedef struct node
{
    int x,y;
}Node;
Node e[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=e[book].x;
                    yy+=e[book].y;
                    if(j>=e[book].x)
                    {
                        dp[j]=max(dp[j-e[book].x]+e[book].y,dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;
    Node temp,q;
    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(e,0,sizeof(e));
    for(int i=1;i<=n;i++)
        cin>>e[i].x;
    for(int j=1;j<=n;j++)
        cin>>e[j].y;
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
int w[maxn],v[maxn];
vector<int>ss[maxn];
void Init(int f[])
{
    for(int i=1;i<=maxn;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=w[book];
                    yy+=v[book];
                    if(j>=w[book])
                    {
                        dp[j]=max(dp[j-w[book]]+v[book],dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;

    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(w,0,sizeof(w));
        memset(v,0,sizeof(v));
    for(int i=1;i<=n;i++)
        cin>>w[i];
    for(int j=1;j<=n;j++)
        cin>>v[j];
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    for(int i=0;i<=n;i++)
    {
        ss[i].clear();
    }
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
vector<int>ss[maxn];
typedef struct node
{
    int x,y;
}Node;
Node e[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=e[book].x;
                    yy+=e[book].y;
                    if(j>=e[book].x)
                    {
                        dp[j]=max(dp[j-e[book].x]+e[book].y,dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;
    Node temp,q;
    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(e,0,sizeof(e));
    for(int i=1;i<=n;i++)
        cin>>e[i].x;
    for(int j=1;j<=n;j++)
        cin>>e[j].y;
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    for(int i=0;i<=n;i++)
    {
        ss[i].clear();
    }
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
vector<int>ss[maxn];
typedef struct node
{
    int x,y;
}Node;
Node e[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=0;j<=p;j++)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=e[book].x;
                    yy+=e[book].y;
                    if(j>=e[book].x)
                    {
                        dp[j]=max(dp[j-e[book].x]+e[book].y,dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;
    Node temp,q;
    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(e,0,sizeof(e));
    for(int i=1;i<=n;i++)
        cin>>e[i].x;
    for(int j=1;j<=n;j++)
        cin>>e[j].y;
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
vector<int>ss[maxn];
typedef struct node
{
    int x,y;
}Node;
Node e[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=e[book].x;
                    yy+=e[book].y;
                    if(j>=e[book].x)
                    {
                        dp[j]=max(dp[j-e[book].x]+e[book].y,dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        ss.clear();
        int xx=0;
    Node temp,q;
    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(e,0,sizeof(e));
    for(int i=1;i<=n;i++)
        cin>>e[i].x;
    for(int j=1;j<=n;j++)
        cin>>e[j].y;
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
vector<int>ss[maxn];
typedef struct node
{
    int x,y;
}Node;
Node e[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=e[book].x;
                    yy+=e[book].y;
                    if(j>=e[book].x)
                    {
                        dp[j]=max(dp[j-e[book].x]+e[book].y,dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;
    Node temp,q;
    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(e,0,sizeof(e));
        memset(ss,0,sizeof(ss));
    for(int i=1;i<=n;i++)
        cin>>e[i].x;
    for(int j=1;j<=n;j++)
        cin>>e[j].y;
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=1005;
int n,m,p;
int dp[maxn];
int f[maxn];
int w[maxn],v[maxn];
vector<int>ss[maxn];
void Init(int f[])
{
    for(int i=1;i<=n+m;i++)
        f[i]=i;
}
int getf(int p)
{
    if(p==f[p])
        return p;
    else{
        f[p]=getf(f[p]);
        return f[p];
    }
}
void mergee(int v,int u)
{
    int t1=getf(v);
    int t2=getf(u);
    if(t1!=t2)
    {
        f[t2]=t1;
    }
}
void beibao()
{
    for(int i=1;i<=n;i++)
    {
        if(f[i]==i)
        {
            for(int j=p;j>=0;j--)
            {
                int xx=0,yy=0;
                for(int k=0;k<ss[i].size();k++)
                {
                    int book=ss[i][k];
                    xx+=w[book];
                    yy+=v[book];
                    if(j>=w[book])
                    {
                        dp[j]=max(dp[j-w[book]]+v[book],dp[j]);
                    }
                }
                if(j>=xx)
                    dp[j]=max(dp[j],dp[j-xx]+yy);
            }
        }
    }
    cout<<dp[p]<<endl;
}
int main()
{
    while(cin>>n>>m>>p)
    {
        int xx=0;

    int a,b;
    int sum1=0,sum2=0;
        memset(dp,0,sizeof(dp));
        memset(w,0,sizeof(w));
        memset(v,0,sizeof(v));
    for(int i=1;i<=n;i++)
        cin>>w[i];
    for(int j=1;j<=n;j++)
        cin>>v[j];
    Init(f);
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
       mergee(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        ss[getf(i)].push_back(i);
    }
    beibao();
    for(int i=0;i<=n;i++)
    {
        ss[i].clear();
    }
    }
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
        lw[0].pb(mw[0]);
    }
    lw[0].pb(0);
    //cout << dp[0][3] << " " << qw << endl;
    for(int i=1;i<qw;i++){
        lw[i%2].clear();
        lw[i%2].pb(0);
        int t = 1 -  i%2;
 //       for(int h = 0;h<lw[t].size();h++){
   //             int u =  lw[t][h];
    //            dp[i][u] = dp[i-1][u];
      //          lw[i%2].pb(u);
        //}
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            int bi = b[ms[i][j]];
            for(int h = 0;h<lw[t].size();h++){
                int u = we + lw[t][h];
                if(u <= l){
                    dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                    lw[i%2].pb(u);
                }
            }
        }
        int we = mw[i];
        int bi = mb[i];
        for(int h = 0;h<lw[t].size();h++){
            int u = we + lw[t][h];
            if(u <= l){
                dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                lw[i%2].pb(u);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        for(int j=0;j<qw;j++)
        ans = max(ans,dp[j][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
        lw[0].pb(mw[0]);
    }
    lw[0].pb(0);
    //cout << dp[0][3] << " " << qw << endl;
    for(int i=1;i<qw;i++){
        lw[i%2].clear();
       // lw[i%2].pb(0);
        int t = 1 -  i%2;
        lw[i%2]=lw[t];
        for(int h = 0;h<lw[t].size();h++){
                int u =  lw[t][h];
                dp[i][u] = dp[i-1][u];
 //               lw[i%2].pb(u);
        }
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            int bi = b[ms[i][j]];
            for(int h = 0;h<lw[t].size();h++){
                int u = we + lw[t][h];
                if(u <= l){
                    dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                    lw[i%2].pb(u);
                }
            }
        }
        int we = mw[i];
        int bi = mb[i];
        for(int h = 0;h<lw[t].size();h++){
            int u = we + lw[t][h];
            if(u <= l){
                dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                lw[i%2].pb(u);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
       // for(int j=0;j<qw;j++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
        lw[0].pb(mw[0]);
    }
    lw[0].pb(0);
    //cout << dp[0][3] << " " << qw << endl;
    for(int i=1;i<qw;i++){

        int t = 1 -  i%2;
        lw[i%2]=lw[t];
        for(int h = 0;h<lw[t].size();h++){
                int u =  lw[t][h];
                dp[i][u] = dp[i-1][u];
        }
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            int bi = b[ms[i][j]];
            for(int h = 0;h<lw[t].size();h++){
                int u = we + lw[t][h];
                if(u <= l){
                    dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                    lw[i%2].pb(u);
                }
            }
        }
        int we = mw[i];
        int bi = mb[i];
        for(int h = 0;h<lw[t].size();h++){
            int u = we + lw[t][h];
            if(u <= l){
                dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                lw[i%2].pb(u);
            }
        }
        ms[i].clear();
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
        lw[0].pb(mw[0]);
    }
    lw[0].pb(0);
    //cout << dp[0][3] << " " << qw << endl;
    for(int i=1;i<qw;i++){
        lw[i%2].clear();
        lw[i%2].pb(0);
        int t = 1 -  i%2;
        for(int h = 0;h<lw[t].size();h++){
                int u =  lw[t][h];
                dp[i][u] = dp[i-1][u];
                lw[i%2].pb(u);
        }
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            int bi = b[ms[i][j]];
            for(int h = 0;h<lw[t].size();h++){
                int u = we + lw[t][h];
                if(u <= l){
                    dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                    lw[i%2].pb(u);
                }
            }
        }
        int we = mw[i];
        int bi = mb[i];
        for(int h = 0;h<lw[t].size();h++){
            int u = we + lw[t][h];
            if(u <= l){
                dp[i][u] = max(dp[i][u],dp[i-1][lw[t][h]]+bi);
                lw[i%2].pb(u);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
    }
    for(int i=1;i<qw;i++){
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            dp[i][we]= max(dp[i][we],b[ms[i][j]]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i][h], dp[i-1][h-we]+b[ms[i][j]]);
                }
        }
        int we = mw[i];
        dp[i][we]= max(dp[i][we],mb[i]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i][h], dp[i-1][h-we]+mb[i]);
                }
         we = 0;
        for(int h=we+1;h<=l;h++)
            dp[i][h] =max(dp[i-1][h],dp[i][h]);
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        //lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
    }
    for(int i=1;i<qw;i++){
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            dp[i][we]= max(dp[i][we],b[ms[i][j]]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+b[ms[i][j]]);
                }
        }
        int we = mw[i];
        dp[i][we]= max(dp[i][we],mb[i]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+mb[i]);
                }
         we = 0;
        dp[i][we]= max(dp[i][we],0);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+0);
                }
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


//In The Name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
long long int a,c,d,n,m,k,l,g;
int b[1005],w[1005],mb[1005],mw[1005];
int dp[1005][1005];
vector <int>v[1005];
vector <int>lw[2];
vector <int>ms[1005];
bool mrk[1005];
int dfs(int x,int q){
    mrk[x] = 1;
    ms[q].pb(x);
    mb[q]+=b[x];
    mw[q]+=w[x];
    for(int i=0;i<v[x].size();i++){
        if(!mrk[v[x][i]]){
            dfs(v[x][i],q);
        }
    }
}
int main(){
    cin >> n >> m >> l ;
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a,&d), v[a].pb(d),v[d].pb(a);
    int qw=0;
    for(int i=1;i<=n;i++){
        if(!mrk[i]){
            dfs(i,qw);
            qw++;
        }
    }
    for(int i=0;i<ms[0].size();i++){
        if(w[ms[0][i]] <= l){
        dp[0][w[ms[0][i]]] = max(dp[0][w[ms[0][i]]],b[ms[0][i]]);
        //lw[0].pb(w[ms[0][i]]);
        }
    }
    if(mw[0] <=l){
        dp[0][mw[0]] = max(dp[0][mw[0]],mb[0]);
    }
    for(int i=1;i<qw;i++){
        for(int j=0;j<ms[i].size();j++){
            int we = w[ms[i][j]];
            dp[i][we]= max(dp[i][we],b[ms[i][j]]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+b[ms[i][j]]);
                }
        }
        int we = mw[i];
        //sd
        dp[i][we]= max(dp[i][we],mb[i]);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+mb[i]);
                }
         we = 0;
        dp[i][we]= max(dp[i][we],0);
            for(int h=we+1;h<=l;h++)
                if(dp[i-1][h-we]){
                    dp[i][h] = max(dp[i-1][h], dp[i-1][h-we]+0);
                }
    }
    int ans = 0;
    for(int i=1;i<=l;i++)
        ans = max(ans,dp[qw-1][i]);
    cout << ans << endl;
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <utility>
#include <fstream>
#include <climits>
#include <complex>
#include <new>
#include <memory>
#include <time.h>
//#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sc scanf
#define ll long long int

#define sc1i(a) sc("%d",&a)
#define sc2i(a,b) sc("%d%d",&a,&b)
#define sc3i(a,b,c) sc("%d%d%d",&a,&b,&c)
#define sc4i(a,b,c,d) sc("%d%d%d%d",&a,&b,&c,&d)

#define sc1ll(a) sc("%lld",&a)
#define sc2ll(a,b) sc("%lld%lld",&a,&b)
#define sc3ll(a,b,c) sc("%lld%lld%lld",&a,&b,&c)
#define sc4ll(a,b,c,d) sc("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pb push_back
#define pi acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define all(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define MP make_pair
#define ppcnt(a) __builtin_popcount(a)
#define cnttz(a) __builtin_ctz(a)
#define cntlz(a) __builtin_clz(a)

#define rep(i,k,n) for(__typeof(k>n?k:n)i = k; k <= n ? i <= n:i >= n;k <= n ? i+=1:i-=1)
#define show(a) cout << #a << " is " << a << endl;

#define wait system("pause")
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};//4 side move
//int dy[]= {-1,1,0,0};//4 side move
//int dx[]= {1,1,0,-1,-1,-1,0,1};//8 side move
//int dy[]= {0,1,1,1,0,-1,-1,-1};//8 side move
//int dx[]={1,1,2,2,-1,-1,-2,-2};//knight move
//int dy[]={2,-2,1,-1,2,-2,1,-1};//knight move

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}//N^P
template<class T> T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}//gcd(a,b)

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cout<< v <<" ";
        return *this;
    }
}dbg;
#define deb(args...) {dbg,args; cerr<<endl;}

void make_unique(vector<int> &a){ sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end()); }

//ll bigmod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int on(int n,int pos){return n=n|(1<<pos);}
//void off(int &n,int pos){ n = n & ~(1<<pos);}
//bool check(int n,int pos){return (bool)(n&(1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

const int N = (int)2e3+5;

vector<int>g[N] , box[N];
int k , wght[N] , b[N] , dp[1005][1005];
bool vis[N];
int n , m , w;

void reset(){
    rep(i,0,N-5){
        g[i].clear();
        box[i].clear();
        vis[i] = false;
    }
}

void dfs(int u){
    vis[u] = true; box[k].pb(u);
    for(int v : g[u]){
        if(!vis[v])dfs(v);
    }
}

int rec(int pos , int wt){
    if(pos > k)return 0;
    int &ret = dp[pos][wt] ;
    if(ret != -1)return ret;
    int mx = 0 , B , W;
    B = 0 , W = 0;
    mx = max(mx , rec(pos+1 , wt));
    for(int v : box[pos]){
        if(wt+wght[v] <= w)mx = max(mx , rec(pos+1 , wt + wght[v]) + b[v] );
        W += wght[v];
        B += b[v];
    }
    if(wt + W <= w)mx = max(mx , rec(pos+1 , wt+W) + B );
    return ret = mx;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
//    freopen("C:/Users/Anwar/Desktop/input.txt","r",stdin);
    #endif
    int u , v;
    while(sc3i(n,m,w) != EOF){
        reset();
        rep(i,1,n)sc1i(wght[i]);
        rep(i,1,n)sc1i(b[i]);
        rep(i,1,m){
            sc2i(u,v);
            g[u].pb(v);
            g[v].pb(u);
        }
        k = 0 ;
        rep(i,1,n){
            if(!vis[i]){
                ++k; dfs(i);
            }
        }
        mem(dp,-1);
        int ans = rec(1,0);
        pf("%d\n",ans);
    }
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <utility>
#include <fstream>
#include <climits>
#include <complex>
#include <new>
#include <memory>
#include <time.h>
//#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sc scanf
#define ll long long int

#define sc1i(a) sc("%d",&a)
#define sc2i(a,b) sc("%d%d",&a,&b)
#define sc3i(a,b,c) sc("%d%d%d",&a,&b,&c)
#define sc4i(a,b,c,d) sc("%d%d%d%d",&a,&b,&c,&d)

#define sc1ll(a) sc("%lld",&a)
#define sc2ll(a,b) sc("%lld%lld",&a,&b)
#define sc3ll(a,b,c) sc("%lld%lld%lld",&a,&b,&c)
#define sc4ll(a,b,c,d) sc("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pb push_back
#define pi acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define all(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define MP make_pair
#define ppcnt(a) __builtin_popcount(a)
#define cnttz(a) __builtin_ctz(a)
#define cntlz(a) __builtin_clz(a)

#define rep(i,k,n) for(__typeof(n)i = k ; i <= n; i++)
#define rrep(i,k,n) for(__typeof(k)i = k ; i >= n; i--)
#define show(x) cout << #x << " is " << x << endl;

#define wait system("pause")
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};//4 side move
//int dy[]= {-1,1,0,0};//4 side move
//int dx[]= {1,1,0,-1,-1,-1,0,1};//8 side move
//int dy[]= {0,1,1,1,0,-1,-1,-1};//8 side move
//int dx[]={1,1,2,2,-1,-1,-2,-2};//knight move
//int dy[]={2,-2,1,-1,2,-2,1,-1};//knight move

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}//N^P
template<class T> T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}//gcd(a,b)

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cout<< v <<" ";
        return *this;
    }
}dbg;
#define deb(args...) {dbg,args; cerr<<endl;}

void make_unique(vector<int> &a){ sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end()); }

//ll bigmod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int on(int n,int pos){return n=n|(1<<pos);}
//void off(int &n,int pos){ n = n & ~(1<<pos);}
//bool check(int n,int pos){return (bool)(n&(1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

const int N = (int)1e3+5;

int n , m , w , k , b[N] , wght[N];
ll dp[N][N];
bool vis[N];
vector<int>g[N] , box[N] ;

void init(){
    rep(i,0,N-3){
        g[i].clear();
        box[i].clear();
        vis[i] = false;
//        wght[i] = 0;
//        b[i] = 0;
    }
}

void dfs(int u){
    vis[u] = true; box[k].pb(u);
    for(int v : g[u]){
        if(!vis[v])dfs(v);
    }
}

ll rec(int pos , int wt){
    if(pos > k)return 0;
    ll &ret = dp[pos][wt];
    if(ret != -1)return ret;
    ret = rec(pos+1 , wt);
    int B = 0 , W = 0;
    for(int v : box[pos]){
        if(wt + wght[v] <= w)ret = max(ret , rec(pos+1,wt+wght[v]) + b[v] );
        W += wght[v]; B += b[v];
    }
    if(wt + W <= w)ret = max(ret , rec(pos+1,wt+W) + B);
    return ret;
}

int main()
{
    #ifndef ONLINE_JUDGE
    //Read;
//    freopen("input.txt","r",stdin);
//    freopen("C:/Users/Anwar/Desktop/input.txt","r",stdin);
    #endif
    int u , v;
    while(sc3i(n ,m , w) != EOF){
        init();
        rep(i,1,n)sc1i(wght[i]);
        rep(i,1,n)sc1i(b[i]);
        rep(i,1,m){
            sc2i(u,v);
            g[u].pb(v);
            g[v].pb(u);
        }
        k = 0;
        rep(i,1,n){
            if(!vis[i]){
                ++k; dfs(i);
            }
        }
        mem(dp,-1);
        ll ans = rec(1,0);
        pf("%lld\n",ans);
    }
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <utility>
#include <fstream>
#include <climits>
#include <complex>
#include <new>
#include <memory>
#include <time.h>
//#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sc scanf
#define ll long long int

#define sc1i(a) sc("%d",&a)
#define sc2i(a,b) sc("%d%d",&a,&b)
#define sc3i(a,b,c) sc("%d%d%d",&a,&b,&c)
#define sc4i(a,b,c,d) sc("%d%d%d%d",&a,&b,&c,&d)

#define sc1ll(a) sc("%lld",&a)
#define sc2ll(a,b) sc("%lld%lld",&a,&b)
#define sc3ll(a,b,c) sc("%lld%lld%lld",&a,&b,&c)
#define sc4ll(a,b,c,d) sc("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pb push_back
#define pi acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define all(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define MP make_pair
#define ppcnt(a) __builtin_popcount(a)
#define cnttz(a) __builtin_ctz(a)
#define cntlz(a) __builtin_clz(a)

#define rep(i,k,n) for(__typeof(k>n?k:n)i = k; k <= n ? i <= n:i >= n;k <= n ? i+=1:i-=1)
#define show(a) cout << #a << " is " << a << endl;

#define wait system("pause")
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};//4 side move
//int dy[]= {-1,1,0,0};//4 side move
//int dx[]= {1,1,0,-1,-1,-1,0,1};//8 side move
//int dy[]= {0,1,1,1,0,-1,-1,-1};//8 side move
//int dx[]={1,1,2,2,-1,-1,-2,-2};//knight move
//int dy[]={2,-2,1,-1,2,-2,1,-1};//knight move

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}//N^P
template<class T> T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}//gcd(a,b)

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cout<< v <<" ";
        return *this;
    }
}dbg;
#define deb(args...) {dbg,args; cerr<<endl;}

void make_unique(vector<int> &a){ sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end()); }

//ll bigmod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int on(int n,int pos){return n=n|(1<<pos);}
//void off(int &n,int pos){ n = n & ~(1<<pos);}
//bool check(int n,int pos){return (bool)(n&(1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

const int N = (int)2e3+5;

vector<int>g[N] , box[N];
int k , wght[N] , b[N] , dp[1005][1005];
bool vis[N];
int n , m , w;

void reset(){
    rep(i,0,N-5){
        g[i].clear();
        box[i].clear();
        vis[i] = false;
        b[i] = wght[i] = 0;
    }
}

void dfs(int u){
    vis[u] = true; box[k].pb(u);
    for(int v : g[u]){
        if(!vis[v])dfs(v);
    }
}

int rec(int pos , int wt){
    if(pos > k)return 0;
    int &ret = dp[pos][wt] ;
    if(ret != -1)return ret;
    int mx = 0 , B , W;
    B = 0 , W = 0;
    mx = max(mx , rec(pos+1 , wt));
    for(int v : box[pos]){
        if(wt+wght[v] <= w)mx = max(mx , rec(pos+1 , wt + wght[v]) + b[v] );
        W += wght[v];
        B += b[v];
    }
    if(wt + W <= w)mx = max(mx , rec(pos+1 , wt+W) + B );
    return ret = mx;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
//    freopen("C:/Users/Anwar/Desktop/input.txt","r",stdin);
    #endif
    int u , v;
    while(sc3i(n,m,w) != EOF){
        reset();
        rep(i,1,n)sc1i(wght[i]);
        rep(i,1,n)sc1i(b[i]);
        rep(i,1,m){
            sc2i(u,v);
            g[u].pb(v);
            g[v].pb(u);
        }
        k = 0 ;
        rep(i,1,n){
            if(!vis[i]){
                ++k; dfs(i);
            }
        }
        mem(dp,-1);
        int ans = rec(1,0);
        pf("%d\n",ans);
    }
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <utility>
#include <fstream>
#include <climits>
#include <complex>
#include <new>
#include <memory>
#include <time.h>
//#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sc scanf
#define ll long long int

#define sc1i(a) sc("%d",&a)
#define sc2i(a,b) sc("%d%d",&a,&b)
#define sc3i(a,b,c) sc("%d%d%d",&a,&b,&c)
#define sc4i(a,b,c,d) sc("%d%d%d%d",&a,&b,&c,&d)

#define sc1ll(a) sc("%lld",&a)
#define sc2ll(a,b) sc("%lld%lld",&a,&b)
#define sc3ll(a,b,c) sc("%lld%lld%lld",&a,&b,&c)
#define sc4ll(a,b,c,d) sc("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pb push_back
#define pi acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define all(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define MP make_pair
#define ppcnt(a) __builtin_popcount(a)
#define cnttz(a) __builtin_ctz(a)
#define cntlz(a) __builtin_clz(a)

#define rep(i,k,n) for(__typeof(k>n?k:n)i = k; k <= n ? i <= n:i >= n;k <= n ? i+=1:i-=1)
#define show(a) cout << #a << " is " << a << endl;

#define wait system("pause")
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};//4 side move
//int dy[]= {-1,1,0,0};//4 side move
//int dx[]= {1,1,0,-1,-1,-1,0,1};//8 side move
//int dy[]= {0,1,1,1,0,-1,-1,-1};//8 side move
//int dx[]={1,1,2,2,-1,-1,-2,-2};//knight move
//int dy[]={2,-2,1,-1,2,-2,1,-1};//knight move

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}//N^P
template<class T> T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}//gcd(a,b)

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cout<< v <<" ";
        return *this;
    }
}dbg;
#define deb(args...) {dbg,args; cerr<<endl;}

void make_unique(vector<int> &a){ sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end()); }

//ll bigmod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int on(int n,int pos){return n=n|(1<<pos);}
//void off(int &n,int pos){ n = n & ~(1<<pos);}
//bool check(int n,int pos){return (bool)(n&(1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

const int N = (int)2e3+5;

vector<int>g[N] , box[N];
int k , wght[N] , b[N] , dp[1005][1005];
bool vis[N];
int n , m , w;

void reset(){
    rep(i,0,N-5){
        g[i].clear();
        box[i].clear();
        vis[i] = false;
    }
}

void dfs(int u){
    vis[u] = true; box[k].pb(u);
    for(int v : g[u]){
        if(!vis[v])dfs(v);
    }
}

int rec(int pos , int wt){
    if(pos > k)return 0;
    int &ret = dp[pos][wt] ;
    if(ret != -1)return ret;
    int mx = 0;
    for(int v : box[pos]){
        if(wt+wght[v] <= w)mx = max(mx , rec(pos+1 , wt + wght[v]) + b[v] );
    }
    return ret = mx;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
//    freopen("C:/Users/Anwar/Desktop/input.txt","r",stdin);
    #endif
    int u , v;
    while(sc3i(n,m,w) != EOF){
        reset();
        rep(i,1,n)sc1i(wght[i]);
        rep(i,1,n)sc1i(b[i]);
        rep(i,1,m){
            sc2i(u,v);
            g[u].pb(v);
            g[v].pb(u);
        }
        k = 0 ;
        rep(i,1,n){
            if(!vis[i]){
                ++k; dfs(i);
            }
        }
        int beauty , weight , nw = n;
        rep(i,1,k){
            beauty = weight = 0;
            for(int v : box[i]){
                beauty += b[v];
                weight += wght[v];
            }
            ++nw;
            wght[nw] = weight;
            b[nw] = beauty;
            box[i].pb(nw);
        }
        mem(dp,-1);
        int ans = rec(1,0);
        pf("%d\n",ans);
    }
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <utility>
#include <fstream>
#include <climits>
#include <complex>
#include <new>
#include <memory>
#include <time.h>
//#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sc scanf
#define ll long long int

#define sc1i(a) sc("%d",&a)
#define sc2i(a,b) sc("%d%d",&a,&b)
#define sc3i(a,b,c) sc("%d%d%d",&a,&b,&c)
#define sc4i(a,b,c,d) sc("%d%d%d%d",&a,&b,&c,&d)

#define sc1ll(a) sc("%lld",&a)
#define sc2ll(a,b) sc("%lld%lld",&a,&b)
#define sc3ll(a,b,c) sc("%lld%lld%lld",&a,&b,&c)
#define sc4ll(a,b,c,d) sc("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pb push_back
#define pi acos(-1.0)
#define mem(a,x) memset(a,x,sizeof(a))
#define all(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define MP make_pair
#define ppcnt(a) __builtin_popcount(a)
#define cnttz(a) __builtin_ctz(a)
#define cntlz(a) __builtin_clz(a)

#define rep(i,k,n) for(__typeof(k>n?k:n)i = k; k <= n ? i <= n:i >= n;k <= n ? i+=1:i-=1)
#define show(x) cout << #x << " is " << x << endl;

#define wait system("pause")
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);

//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};//4 side move
//int dy[]= {-1,1,0,0};//4 side move
//int dx[]= {1,1,0,-1,-1,-1,0,1};//8 side move
//int dy[]= {0,1,1,1,0,-1,-1,-1};//8 side move
//int dx[]={1,1,2,2,-1,-1,-2,-2};//knight move
//int dy[]={2,-2,1,-1,2,-2,1,-1};//knight move

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}//N^P
template<class T> T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}//gcd(a,b)

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cout<< v <<" ";
        return *this;
    }
}dbg;
#define deb(args...) {dbg,args; cerr<<endl;}

void make_unique(vector<int> &a){ sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end()); }

//ll bigmod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int on(int n,int pos){return n=n|(1<<pos);}
//void off(int &n,int pos){ n = n & ~(1<<pos);}
//bool check(int n,int pos){return (bool)(n&(1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

const int N = (int)1e3+5;

int n , m , w , k , b[N] , wght[N];
int dp[N][N];
bool vis[N];
vector<int>g[N] , box[N] ;

void init(){
    rep(i,0,N-2){
        g[i].clear();
        box[i].clear();
        vis[i] = false;
        wght[i] = 0;
        b[i] = 0;
    }
}

void dfs(int u){
    vis[u] = true; box[k].pb(u);
    for(int v : g[u]){
        if(!vis[v])dfs(v);
    }
}

int rec(int pos , int wt){
    if(pos > k)return 0;
    int &ret = dp[pos][wt];
    if(ret != -1)return ret;
    ret = rec(pos+1 , wt);
    int B = 0 , W = 0;
    for(int v : box[pos]){
        if(wt + wght[v] <= w)ret = max(ret , rec(pos+1,wt+wght[v]) + b[v] );
        W += wght[v]; B += b[v];
    }
    if(wt + W <= w)ret = max(ret , rec(pos+1,wt+W) + B);
    return ret;
}

int main()
{
    #ifndef ONLINE_JUDGE
    //Read;
    freopen("input.txt","r",stdin);
//    freopen("C:/Users/Anwar/Desktop/input.txt","r",stdin);
    #endif
    int u , v;
    while(sc3i(n ,m , w) != EOF){
        init();
        rep(i,1,n)sc1i(wght[i]);
        rep(i,1,n)sc1i(b[i]);
        rep(i,1,m){
            sc2i(u,v);
            g[u].pb(v);
            g[v].pb(u);
        }
        k = 0;
        rep(i,1,n){
            if(!vis[i]){
                ++k; dfs(i);
            }
        }
        mem(dp,-1);
        int ans = rec(1,0);
        pf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const int mod = 1e9 + 7;
const ll LINF = 4e18 + 10;

#define fr first
#define sc second
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(),x.end()
#define speed_up ios_base::sync_with_stdio(0);cin.tie(0)
#define fname ""

int n, m, w, wg[N3], cu[N3], col, cwg[N3], ccu[N3];
int d[N3][N3][2], temp1, temp2;
bool u[N3];
vector <int> v[N3], comp[N3];

void dfs(int x){
	temp1 += wg[x];
	temp2 += cu[x];
	u[x] = 1;
	comp[col].pb(x);
	for(int i = 0; i < v[x].size(); ++ i){
		int to = v[x][i];
		if(!u[to]){
			dfs(to);
		}
	}
}

int main(){
	cin >> n >> m >> w;
	for(int i = 1; i <= n; ++ i){
		cin >> wg[i];
	}
	for(int i = 1; i <= n; ++ i){
		cin >> cu[i];
	}
	for(int i = 1; i <= m; ++ i){
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i = 1; i <= n; ++ i){
		if(!u[i]){
			temp1 = 0;
			temp2 = 0;
			col ++;
			dfs(i);
			cwg[col] = temp1;
			ccu[col] = temp2;
		}
	}
	for(int i = 1; i <= col; ++ i){
		for(int j = 1; j <= w; ++ j){
			d[i][j][0] = INF;
			d[i][j][1] = INF;
		}
	}
	d[0][0][0] = 0;
	d[0][0][1] = 0;
	for(int i = 1; i <= col; ++ i){
		for(int x = 0; x <= w; ++ x){
			d[i][x][0] = d[i - 1][x][0];
			d[i][x][1] = d[i - 1][x][1];
			if(x - cwg[i] >= 0 && d[i][x][0] < (d[i - 1][x - cwg[i]][0] + ccu[i])){
				d[i][x][0] = d[i - 1][x - cwg[i]][0] + ccu[i];
			}
		}

		for(auto pos : comp[i]){
			for(int wgh = 0; wgh <= w; ++ wgh){
				if(wgh - wg[pos] >= 0 && d[i][wgh][1] < d[i - 1][wgh - wg[pos]][1] + cu[pos]){
					d[i][wgh][1] = d[i - 1][wgh - wg[pos]][1] + cu[pos];
				}
			}
		}
	}
	cout << max(d[col][w][0], d[col][w][1]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const int mod = 1e9 + 7;
const ll LINF = 4e18 + 10;

#define fr first
#define sc second
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(),x.end()
#define speed_up ios_base::sync_with_stdio(0);cin.tie(0)
#define fname ""

ll n, m, w, wg[N3], cu[N3], col, cwg[N3], ccu[N3];
ll d[N3][N3][2];
bool u[N3];
vector <int> v[N3], comp[N3];

void dfs(int x){
	u[x] = 1;
	cwg[col] += wg[x];
	ccu[col] += cu[x];
	comp[col].pb(x);
	for(int i = 0; i < v[x].size(); ++ i){
		int to = v[x][i];
		if(!u[to]){
			dfs(to);
		}
	}
}

int main(){
	cin >> n >> m >> w;
	for(int i = 1; i <= n; ++ i){
		cin >> wg[i];
	}
	for(int i = 1; i <= n; ++ i){
		cin >> cu[i];
	}
	for(int i = 1; i <= m; ++ i){
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i = 1; i <= n; ++ i){
		if(!u[i]){
			col ++;
			dfs(i);
		}
	}
	for(int i = 1; i <= col; ++ i){
		for(int j = 1; j <= w; ++ j){
			d[i][j][0] = INF;
			d[i][j][1] = INF;
		}
	}
	d[0][0][0] = 0;
	d[0][0][1] = 0;
	for(int i = 1; i <= col; ++ i){
		for(int x = 0; x <= w; ++ x){
			d[i][x][0] = min(d[i - 1][x][0], d[i][x][0]);
			d[i][x][1] = min(d[i - 1][x][1], d[i][x][1]);
			if(x - cwg[i] >= 0 && d[i][x][0] <= (d[i - 1][x - cwg[i]][0] + ccu[i])){
				d[i][x][0] = d[i - 1][x - cwg[i]][0] + ccu[i];
			}
		}
		for(int x = 0; x <= w; ++ x){
			for(auto pos : comp[i]){
				if(x - wg[pos] >= 0 && d[i][x][1] <= (d[i - 1][x - wg[pos]][1] + cu[pos])){
					d[i][x][1] = d[i - 1][x - wg[pos]][1] + cu[pos];
				}
			}
		}
	}
	cout << max(d[col][w][0], d[col][w][1]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const int mod = 1e9 + 7;
const ll LINF = 4e18 + 10;

#define fr first
#define sc second
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(),x.end()
#define speed_up ios_base::sync_with_stdio(0);cin.tie(0)
#define fname ""

ll n, m, w, col;
ll wg[N3], cu[N3], cwg[N3], ccu[N3];
ll d[N3][N3][2];
bool u[N3];
vector <int> v[N3], comp[N3];

void dfs(int x){
	u[x] = 1;
	cwg[col] += wg[x];
	ccu[col] += cu[x];
	comp[col].pb(x);
	for(auto to : v[x]){
		if(!u[to]){
			dfs(to);
		}
	}
}

int main(){
	cin >> n >> m >> w;
	for(int i = 1; i <= n; ++ i){
		cin >> wg[i];
	}
	for(int i = 1; i <= n; ++ i){
		cin >> cu[i];
	}
	for(int i = 1; i <= m; ++ i){
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i = 1; i <= n; ++ i){
		if(!u[i]){
			col ++;
			dfs(i);
		}
	}
	for(int i = 1; i <= col; ++ i){
		for(int j = 1; j <= w; ++ j){
			d[i][j][0] = INF;
			d[i][j][1] = INF;
		}
	}
	d[0][0][0] = 0;
	d[0][0][1] = 0;
	for(int i = 1; i <= col; ++ i){
		for(int x = 0; x <= w; ++ x){
			d[i][x][0] = min(d[i - 1][x][0], d[i][x][0]);
			d[i][x][1] = min(d[i - 1][x][1], d[i][x][1]);
			if(x - cwg[i] >= 0){
				if(d[i][x][0] <= (d[i - 1][x - cwg[i]][0] + ccu[i])){
					d[i][x][0] = d[i - 1][x - cwg[i]][0] + ccu[i];
				}
				if(d[i][x][0] <= (d[i - 1][x - cwg[i]][1] + ccu[i])){
					d[i][x][0] = d[i - 1][x - cwg[i]][1] + ccu[i];
				}
			}
		}
		for(int x = 0; x <= w; ++ x){
			for(auto pos : comp[i]){
				if(x - wg[pos] >= 0){
					if(d[i][x][1] <= (d[i - 1][x - wg[pos]][1] + cu[pos])){
						d[i][x][1] = d[i - 1][x - wg[pos]][1] + cu[pos];
					}
					if(d[i][x][1] <= (d[i - 1][x - wg[pos]][0] + cu[pos])){
						d[i][x][1] = d[i - 1][x - wg[pos]][0] + cu[pos];
					}
				}
			}
		}
	}
	cout << max(d[col][w][0], d[col][w][1]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const int mod = 1e9 + 7;
const ll LINF = 4e18 + 10;

#define fr first
#define sc second
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(),x.end()
#define speed_up ios_base::sync_with_stdio(0);cin.tie(0)
#define fname ""

ll n, m, w, wg[N3], cu[N3], col, cwg[N3], ccu[N3];
ll d[N3][N3][2], temp1, temp2;
bool u[N3];
vector <int> v[N3], comp[N3];

void dfs(int x){
	temp1 += wg[x];
	temp2 += cu[x];
	u[x] = 1;
	comp[col].pb(x);
	for(int i = 0; i < v[x].size(); ++ i){
		int to = v[x][i];
		if(!u[to]){
			dfs(to);
		}
	}
}

int main(){
	cin >> n >> m >> w;
	for(int i = 1; i <= n; ++ i){
		cin >> wg[i];
	}
	for(int i = 1; i <= n; ++ i){
		cin >> cu[i];
	}
	for(int i = 1; i <= m; ++ i){
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i = 1; i <= n; ++ i){
		if(!u[i]){
			temp1 = 0;
			temp2 = 0;
			col ++;
			dfs(i);
			cwg[col] = temp1;
			ccu[col] = temp2;
		}
	}
	for(int i = 1; i <= col; ++ i){
		for(int j = 1; j <= w; ++ j){
			d[i][j][0] = INF;
			d[i][j][1] = INF;
		}
	}
	d[0][0][0] = 0;
	d[0][0][1] = 0;
	for(int i = 1; i <= col; ++ i){
		for(int x = 0; x <= w; ++ x){
			d[i][x][0] = d[i - 1][x][0];
			d[i][x][1] = d[i - 1][x][1];
			if(x - cwg[i] >= 0 && d[i][x][0] < (d[i - 1][x - cwg[i]][0] + ccu[i])){
				d[i][x][0] = d[i - 1][x - cwg[i]][0] + ccu[i];
			}
		}

		for(auto pos : comp[i]){
			for(int wgh = 0; wgh <= w; ++ wgh){
				if(wgh - wg[pos] >= 0 && d[i][wgh][1] < d[i - 1][wgh - wg[pos]][1] + cu[pos]){
					d[i][wgh][1] = d[i - 1][wgh - wg[pos]][1] + cu[pos];
				}
			}
		}
	}
	cout << max(d[col][w][0], d[col][w][1]);
	return 0;
}


// AUTHOR: ARVIND NAIR

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

#define TEST  int test_case; scanf("%d",&test_case); while(test_case--)
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);
#define rep(a,c)   for ( int (a)=0; (a)<(c); (a)++)
#define repn(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
#define repd(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
#define FOR(arr) for(auto &i:arr)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define EPS (double)(1e-9)
#define MOD 1000000007
#define M(x,i) memset(x,i,sizeof(x))
#define CLR(x) x.clear()
#define sz(x) (int)(x.size())
#define si(n) scanf("%d",&n)
#define gi(n) printf("%d\n",n)

int tim;
vi g[1005];
vector<pi> comp[1005];
bool vis[1005];
int w[1005],b[1005];
int dp[1005][1005];
vi beauty,weight;
int sum1,sum2;

void dfs(int u, int p) {

	comp[tim].pb({w[u],b[u]});
	vis[u]=true;
	sum1+=w[u];
	sum2+=b[u];

    rep(i,sz(g[u])) {

    	 int v=g[u][i];
    	 if(v!=p)
    	 	dfs(v,u);
    }
}

int main() {

	M(vis,0);

int n,m,x; si(n); si(m); si(x);

 repn(i,1,n) si(w[i]);
 repn(i,1,n) si(b[i]);

 rep(i,m) {

 	 int x,y; si(x); si(y);
 	 g[x].pb(y);
 	 g[y].pb(x);
 }

 repn(i,1,n) {

 if(!vis[i]) {
 	++tim,sum1=sum2=0;
 dfs(i,0);
   weight.pb(sum1);
   beauty.pb(sum2);
  }
}

 repn(i,1,tim)
 	 repn(j,1,x) {

 	     if(weight[i-1]<=j)
             dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+beauty[i-1]);
         else
         	dp[i][j]=dp[i-1][j];

 	      rep(k,sz(comp[i])) {

             if(comp[i][k].fi<=j)
              dp[i][j]=max(dp[i][j],dp[i-1][j-comp[i][k].fi]+comp[i][k].se);

 	 }
 }

 int ans=0;

 repn(i,1,x)
 ans=max(ans,dp[tim][i]);

 cout<<ans;

return 0;
}


// AUTHOR: ARVIND NAIR

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

#define TEST  int test_case; scanf("%d",&test_case); while(test_case--)
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);
#define rep(a,c)   for ( int (a)=0; (a)<(c); (a)++)
#define repn(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
#define repd(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
#define FOR(arr) for(auto &i:arr)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define EPS (double)(1e-9)
#define MOD 1000000007
#define M(x,i) memset(x,i,sizeof(x))
#define CLR(x) x.clear()
#define sz(x) (int)(x.size())
#define si(n) scanf("%d",&n)
#define gi(n) printf("%d\n",n)

int tim;
vi g[1005];
vector<pi> comp[1005];
bool vis[1005];
int w[1005],b[1005];
int dp[2][1005];
vi beauty,weight;
int sum1,sum2;

void dfs(int u, int p) {

	comp[tim].pb({w[u],b[u]});
	vis[u]=true;
	sum1+=w[u];
	sum2+=b[u];

    rep(i,sz(g[u])) {

    	 int v=g[u][i];
    	 if(v!=p)
    	 	dfs(v,u);
    }
}

int main() {

	M(vis,0);

int n,m,x; si(n); si(m); si(x);

 repn(i,1,n) si(w[i]);
 repn(i,1,n) si(b[i]);

 rep(i,m) {

 	 int x,y; si(x); si(y);
 	 g[x].pb(y);
 	 g[y].pb(x);
 }

 repn(i,1,n) {

 if(!vis[i]) {
 	++tim,sum1=sum2=0;
 dfs(i,0);
   weight.pb(sum1);
   beauty.pb(sum2);
  }
}

 repn(i,1,tim) {

 	int cur=i&1;
 	int prev=cur^1;
 	 repn(j,1,x) {

 	     if(weight[i-1]<=j)
             dp[cur][j]=max(dp[prev][j],dp[prev][j-weight[i-1]]+beauty[i-1]);
         else
         	dp[cur][j]=dp[prev][j];

 	      rep(k,sz(comp[i])) {

             if(comp[i][k].fi<=j)
              dp[cur][j]=max(dp[cur][j],dp[prev][j-comp[i][k].fi]+comp[i][k].se);

 	 }
 }
}

 int ans=0;

 repn(i,1,x)
 ans=max(ans,dp[tim&1][i]);

 cout<<ans;

return 0;
}


// AUTHOR: ARVIND NAIR

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

#define TEST  int test_case; scanf("%d",&test_case); while(test_case--)
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);
#define rep(a,c)   for ( int (a)=0; (a)<(c); (a)++)
#define repn(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
#define repd(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
#define FOR(arr) for(auto &i:arr)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define EPS (double)(1e-9)
#define MOD 1000000007
#define M(x,i) memset(x,i,sizeof(x))
#define CLR(x) x.clear()
#define sz(x) (int)(x.size())
#define si(n) scanf("%d",&n)
#define gi(n) printf("%d\n",n)

int tim;
vi g[1005],comp[1005];
bool vis[1005];
int w[1005],b[1005];
int dp[2][1005];
vi beauty,weight;
int sum1,sum2;

void dfs(int u, int p) {

	comp[tim].pb(u);
	vis[u]=true;
	sum1+=w[u];
	sum2+=b[u];

    rep(i,sz(g[u])) {

    	 int v=g[u][i];
    	 if(!vis[v])
    	 	dfs(v,u);
    }
}

int main() {

	M(vis,0);

int n,m,x; si(n); si(m); si(x);

 repn(i,1,n) si(w[i]);
 repn(i,1,n) si(b[i]);

 rep(i,m) {

 	 int x,y; si(x); si(y);
 	 g[x].pb(y);
 	 g[y].pb(x);
 }

 repn(i,1,n) {

 if(!vis[i]) {
 	++tim,sum1=sum2=0;
 dfs(i,0);
   weight.pb(sum1);
   beauty.pb(sum2);
  }
}

 repn(i,1,tim) {

 	int cur=i&1;
 	int prev=cur^1;
 	 repn(j,1,x) {

 	     if(weight[i-1]<=j)
             dp[cur][j]=max(dp[prev][j],dp[prev][j-weight[i-1]]+beauty[i-1]);
         else
         	dp[cur][j]=dp[prev][j];

 	      rep(k,sz(comp[i])) {

             if(w[comp[i][k]]<=j)
              dp[cur][j]=max(dp[cur][j],dp[prev][j-w[comp[i][k]]]+b[comp[i][k]]);

 	 }
 }
}

 int ans=0;

 repn(i,1,x)
 ans=max(ans,dp[tim&1][i]);

 cout<<ans;

return 0;
}


// AUTHOR: ARVIND NAIR

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

#define TEST  int test_case; scanf("%d",&test_case); while(test_case--)
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);
#define rep(a,c)   for ( int (a)=0; (a)<(c); (a)++)
#define repn(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
#define repd(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
#define FOR(arr) for(auto &i:arr)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define EPS (double)(1e-9)
#define MOD 1000000007
#define M(x,i) memset(x,i,sizeof(x))
#define CLR(x) x.clear()
#define sz(x) (int)(x.size())
#define si(n) scanf("%d",&n)
#define gi(n) printf("%d\n",n)

int tim;
vi g[1005],comp[1005];
bool vis[1005];
int w[1005],b[1005];
int dp[2][1005];
vi beauty,weight;
int sum1,sum2;

void dfs(int u, int p) {

	comp[tim].pb(u);
	vis[u]=true;
	sum1+=w[u];
	sum2+=b[u];

    rep(i,sz(g[u])) {

    	 int v=g[u][i];
    	 if(v!=p)
    	 	dfs(v,u);
    }
}

int main() {

	M(vis,0);

int n,m,x; si(n); si(m); si(x);

 repn(i,1,n) si(w[i]);
 repn(i,1,n) si(b[i]);

 rep(i,m) {

 	 int x,y; si(x); si(y);
 	 g[x].pb(y);
 	 g[y].pb(x);
 }

 repn(i,1,n) {

 if(!vis[i]) {
 	++tim,sum1=sum2=0;
 dfs(i,0);
   weight.pb(sum1);
   beauty.pb(sum2);
  }
}

 repn(i,1,tim) {

 	int cur=i&1;
 	int prev=cur^1;
 	 repn(j,1,x) {

 	     if(weight[i-1]<=j)
             dp[cur][j]=max(dp[prev][j],dp[prev][j-weight[i-1]]+beauty[i-1]);
         else
         	dp[cur][j]=dp[prev][j];

 	      rep(k,sz(comp[i])) {

             if(w[comp[i][k]]<=j)
              dp[cur][j]=max(dp[cur][j],dp[prev][j-w[comp[i][k]]]+b[comp[i][k]]);

 	 }
 }
}

 int ans=0;

 repn(i,1,x)
 ans=max(ans,dp[tim&1][i]);

 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000;
const int MAXW = 1000;

struct PERSONA{
    int b;
    int w;
    int componente;

    const bool operator < (const PERSONA& otro) const{
    	return componente < otro.componente;
    }
};

vector<int> rel[MAXN + 2];
int visitado[MAXN + 2];
int sig_componente[MAXN + 2]; /// SIG INDICE DONDE COMIENZA OTRO GRUPO
bool es_inicio_grupo[MAXN + 2];
int peso_grupo[MAXN + 2];
int belleza_grupo[MAXN + 2];
int num_componentes;

PERSONA persona[MAXN + 2];

int dp[MAXN + 2][MAXW + 2];

int N, M;
int W;

void dfs(int nodo){
	visitado[nodo] = num_componentes;
	int tam = rel[nodo].size(), sig;
	for(int i = 0; i < tam; i++){
		sig = rel[nodo][i];
		if(visitado[sig] == 0){
			dfs(sig);
		}
	}
}

void calcula_componentes(){
	for(int i = 1; i <= N; i++){
		if(visitado[i] == 0){
			num_componentes++;
			dfs(i);
		}
	}
}

void asigna_componentes(){
	for(int i = 1; i <= N; i++){
		persona[i].componente = visitado[i];
		peso_grupo[visitado[i]] += persona[i].w;
		belleza_grupo[visitado[i]] += persona[i].b;
	}
}

void calcula_sigs_componentes(){
	for(int i = 1; i <= N; i++){
		if(persona[i - 1].componente == persona[i].componente){
			sig_componente[i] = sig_componente[i - 1];
		}else{
			es_inicio_grupo[i - 1] = true;
			sig_componente[i] = i - 1;
		}
	}
	es_inicio_grupo[N] = true;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M >> W;

	for(int i = 1; i <= N; i++){
		cin >> persona[i].w;
	}

	for(int i = 1; i <= N; i++){
		cin >> persona[i].b;
	}

	int a, b;
	while(M--){
		cin >> a >> b;
		rel[a].push_back(b);
		rel[b].push_back(a);
	}

	calcula_componentes();
	asigna_componentes();
	sort(persona + 1, persona + N + 1);
	calcula_sigs_componentes();

	int mejor;

	int nueva_w;
	int nueva_n;

	for(int w = 1; w <= W; w++){
		for(int n = 1; n <= N; n++){
			mejor = -1;

			nueva_n = sig_componente[n];

			if(es_inicio_grupo[n]){
				///tomo al grupo
				nueva_w = w - peso_grupo[persona[n].componente];
				if(nueva_w >= 0){
					mejor = dp[nueva_n][nueva_w] + belleza_grupo[persona[n].componente];
				}
			}
			/// tomo a este men
			nueva_w = w - persona[n].w;
			if(nueva_w >= 0){
				mejor = max(mejor, dp[nueva_n][nueva_w] + persona[n].b);
			}
			/// rechazo a este men
			mejor = max(mejor, dp[n - 1][w]);

			if(mejor == -1){
				int cero = 0;
				mejor /= cero;
			}
			dp[n][w] = mejor;
		}
	}

	cout << dp[N][W] << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000;
const int MAXW = 1000;

struct PERSONA{
    int b;
    int w;
    int componente;

    const bool operator < (const PERSONA& otro) const{
    	return componente < otro.componente;
    }
};

vector<int> rel[MAXN + 2];
int visitado[MAXN + 2];
int sig_componente[MAXN + 2]; /// SIG INDICE DONDE COMIENZA OTRO GRUPO
bool es_inicio_grupo[MAXN + 2];
int peso_grupo[MAXN + 2];
int belleza_grupo[MAXN + 2];
int num_componentes;

PERSONA persona[MAXN + 2];

int dp[MAXN + 2][MAXW + 2];

int N, M;
int W;

void dfs(int nodo){
	visitado[nodo] = num_componentes;
	int tam = rel[nodo].size(), sig;
	for(int i = 0; i < tam; i++){
		sig = rel[nodo][i];
		if(visitado[sig] == 0){
			dfs(sig);
		}
	}
}

void calcula_componentes(){
	for(int i = 1; i <= N; i++){
		if(visitado[i] == 0){
			num_componentes++;
			dfs(i);
		}
	}
}

void asigna_componentes(){
	for(int i = 1; i <= N; i++){
		persona[i].componente = visitado[i];
		peso_grupo[visitado[i]] += persona[i].w;
		belleza_grupo[visitado[i]] += persona[i].b;
	}
}

void calcula_sigs_componentes(){
	for(int i = 1; i <= N; i++){
		if(persona[i - 1].componente == persona[i].componente){
			sig_componente[i] = sig_componente[i - 1];
		}else{
			es_inicio_grupo[i - 1] = true;
			sig_componente[i] = i - 1;
		}
	}
	es_inicio_grupo[n] = true;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M >> W;

	for(int i = 1; i <= N; i++){
		cin >> persona[i].w;
	}

	for(int i = 1; i <= N; i++){
		cin >> persona[i].b;
	}

	int a, b;
	while(M--){
		cin >> a >> b;
		rel[a].push_back(b);
		rel[b].push_back(a);
	}

	calcula_componentes();
	asigna_componentes();
	sort(persona + 1, persona + N + 1);
	calcula_sigs_componentes();

	int mejor;

	int nueva_w;
	int nueva_n;

	for(int w = 1; w <= W; w++){
		for(int n = 1; n <= N; n++){
			mejor = -1;

			nueva_n = sig_componente[n];

			if(es_inicio_grupo[n]){
				///tomo al grupo
				nueva_w = w - peso_grupo[persona[n].componente];
				if(nueva_w >= 0){
					mejor = dp[nueva_n][nueva_w] + belleza_grupo[persona[n].componente];
				}
			}
			/// tomo a este men
			nueva_w = w - persona[n].w;
			if(nueva_w >= 0){
				mejor = max(mejor, dp[nueva_n][nueva_w] + persona[n].b);
			}
			/// rechazo a este men
			mejor = max(mejor, dp[n - 1][w]);

			if(mejor == -1){
				int cero = 0;
				mejor /= cero;
			}
			dp[n][w] = mejor;
		}
	}

	cout << dp[N][W] << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000;
const int MAXW = 1000;

struct PERSONA{
    int b;
    int w;
    int componente;

    const bool operator < (const PERSONA& otro) const{
    	return componente < otro.componente;
    }
};

vector<int> rel[MAXN + 2];
int visitado[MAXN + 2];
int sig_componente[MAXN + 2]; /// SIG INDICE DONDE COMIENZA OTRO GRUPO
bool es_inicio_grupo[MAXN + 2];
int peso_grupo[MAXN + 2];
int belleza_grupo[MAXN + 2];
int num_componentes;

PERSONA persona[MAXN + 2];

int dp[MAXN + 2][MAXW + 2];

int N, M;
int W;

void dfs(int nodo){
	visitado[nodo] = num_componentes;
	int tam = rel[nodo].size(), sig;
	for(int i = 0; i < tam; i++){
		sig = rel[nodo][i];
		if(visitado[sig] == 0){
			dfs(sig);
		}
	}
}

void calcula_componentes(){
	for(int i = 1; i <= N; i++){
		if(visitado[i] == 0){
			num_componentes++;
			dfs(i);
		}
	}
}

void asigna_componentes(){
	for(int i = 1; i <= N; i++){
		persona[i].componente = visitado[i];
		peso_grupo[visitado[i]] += persona[i].w;
		belleza_grupo[visitado[i]] += persona[i].b;
	}
}

void calcula_sigs_componentes(){
	for(int i = 1; i <= N; i++){
		if(persona[i - 1].componente == persona[i].componente){
			sig_componente[i] = sig_componente[i - 1];
		}else{
			es_inicio_grupo[i - 1] = true;
			sig_componente[i] = i - 1;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M >> W;

	for(int i = 1; i <= N; i++){
		cin >> persona[i].w;
	}

	for(int i = 1; i <= N; i++){
		cin >> persona[i].b;
	}

	int a, b;
	while(M--){
		cin >> a >> b;
		rel[a].push_back(b);
		rel[b].push_back(a);
	}

	calcula_componentes();
	asigna_componentes();
	sort(persona + 1, persona + N + 1);
	calcula_sigs_componentes();

	int mejor;

	int nueva_w;
	int nueva_n;

	for(int w = 1; w <= W; w++){
		for(int n = 1; n <= N; n++){
			mejor = -1;

			nueva_n = sig_componente[n];

			if(es_inicio_grupo[n]){
				///tomo al grupo
				nueva_w = w - peso_grupo[persona[n].componente];
				if(nueva_w >= 0){
					mejor = dp[nueva_n][nueva_w] + belleza_grupo[persona[n].componente];
				}
			}
			/// tomo a este men
			nueva_w = w - persona[n].w;
			if(nueva_w >= 0){
				mejor = max(mejor, dp[nueva_n][nueva_w] + persona[n].b);
			}
			/// rechazo a este men
			mejor = max(mejor, dp[n - 1][w]);
			dp[n][w] = mejor;
		}
	}

	cout << dp[N][W] << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000;
const int MAXW = 1000;

struct PERSONA{
    int b;
    int w;
    int componente;

    const bool operator < (const PERSONA& otro) const{
    	return componente < otro.componente;
    }
};

vector<int> rel[MAXN + 2];
int visitado[MAXN + 2];
int sig_componente[MAXN + 2]; /// SIG INDICE DONDE COMIENZA OTRO GRUPO
bool es_inicio_grupo[MAXN + 2];
int peso_grupo[MAXN + 2];
int belleza_grupo[MAXN + 2];
int num_componentes;

PERSONA persona[MAXN + 2];

int dp[MAXN + 2][MAXW + 2];

int N, M;
int W;

void dfs(int nodo){
	visitado[nodo] = num_componentes;
	int tam = rel[nodo].size(), sig;
	for(int i = 0; i < tam; i++){
		sig = rel[nodo][i];
		if(visitado[sig] == 0){
			dfs(sig);
		}
	}
}

void calcula_componentes(){
	for(int i = 1; i <= N; i++){
		if(visitado[i] == 0){
			num_componentes++;
			dfs(i);
		}
	}
}

void asigna_componentes(){
	for(int i = 1; i <= N; i++){
		persona[i].componente = visitado[i];
		peso_grupo[visitado[i]] += persona[i].w;
		belleza_grupo[visitado[i]] += persona[i].b;
	}
}

void calcula_sigs_componentes(){
	for(int i = 1; i <= N; i++){
		if(persona[i - 1].componente == persona[i].componente){
			sig_componente[i] = sig_componente[i - 1];
		}else{
			es_inicio_grupo[i - 1] = true;
			sig_componente[i] = i - 1;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M >> W;

	for(int i = 1; i <= N; i++){
		cin >> persona[i].w;
	}

	for(int i = 1; i <= N; i++){
		cin >> persona[i].b;
	}

	int a, b;
	while(M--){
		cin >> a >> b;
		rel[a].push_back(b);
		rel[b].push_back(a);
	}

	calcula_componentes();
	asigna_componentes();
	sort(persona + 1, persona + N + 1);
	calcula_sigs_componentes();

	int mejor;

	int nueva_w;
	int nueva_n;

	for(int w = 1; w <= W; w++){
		for(int n = 1; n <= N; n++){
			mejor = -1;

			nueva_n = sig_componente[n];

			if(es_inicio_grupo[n]){
				///tomo al grupo
				nueva_w = w - peso_grupo[persona[n].componente];
				if(nueva_w >= 0){
					mejor = dp[nueva_n][nueva_w] + belleza_grupo[persona[n].componente];
				}
			}
			/// tomo a este men
			nueva_w = w - persona[n].w;
			if(nueva_w >= 0){
				mejor = max(mejor, dp[nueva_n][nueva_w] + persona[n].b);
			}
			/// rechazo a este men
			mejor = max(mejor, dp[n - 1][w]);

			if(mejor == -1){
				int cero = 0;
				mejor /= cero;
			}
			dp[n][w] = mejor;
		}
	}

	cout << dp[N][W] << "\n";
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
int n,m,weight;
int no[1010];
vector <int>f[1010];
int w[1010],b[1010],pre[1010];
long long maxnw[1010],maxb[1010];
long long d[1010][1010];
int find_ds(int a){
	return a== pre[a]?a:pre[a] = find_ds(pre[a]);
}
void combine(int a,int b){
	int fa = find_ds(a),fb = find_ds(b);
	if(fa != fb) pre[fa] = fb;
}
int main(){
	int u,v;
	scanf("%d%d%d",&n,&m,&weight);
	for(int i = 1;i <= n;i ++) {
		scanf("%d",&w[i]);
		pre[i] = i;
	}
	for(int i= 1;i <= n;i ++) scanf("%d",&b[i]);
	for(int i = 1;i <= m;i ++){
		scanf("%d%d",&u,&v);
		combine(u,v);
	}
	int maxn = 0;
	for(int i = 1;i <= n;i ++){
		int tmp = find_ds(i);
		if(!no[tmp]) no[tmp] = ++maxn;
		f[no[tmp]].push_back(i);
		maxnw[no[tmp]] += w[i];
		maxb[no[tmp]] += b[i];
	}
	for(int k = 0;k < f[1].size();k ++){
		int nowno = f[1][k];
		if(w[nowno] <= weight) d[1][nowno] = max(d[1][w[nowno]],(long long)b[nowno]);
	}
	if(maxnw[1] <= weight) d[1][maxnw[1]] = max(d[1][maxnw[1]],maxb[1]);
	for(int i = 1;i < maxn;i ++){
		for(int j = weight;j >= 0;j --){
			d[i + 1][j] = d[i][j];
			for(int k = 0;k < f[i + 1].size();k++){
				int nowno = f[i + 1][k];
				if(w[nowno] + j <= weight) d[i + 1][j + w[nowno]] = max(d[i + 1][j + w[nowno]],d[i][j] + b[nowno]);
			}
			if(maxnw[i + 1] + j <= weight) d[i + 1][j + maxnw[i + 1]] = max(d[i + 1][j + maxnw[i + 1]],d[i][j] + maxb[i+1]);
		}
	}
	long long ans = 0;
	for(int i = 0;i <= weight;i++) ans = max(ans,d[maxn][i]);
	printf("%I64d\n",ans );
	return 0;
}