#include<bits/stdc++.h>
#define N 1000
#define ll long long
#define pb push_back
#define INF -3000000000
using namespace std;

vector<int> adj[ N+5 ], gp[ N+5 ];
int W[ N+5 ], B[ N+5 ], G[ N+5 ], Ba[ N+5 ], Wa[ N+5 ];
bool vis[ N+5 ], done[ N+5 ][ N+5 ];
ll dp[ N+5 ][ N+5 ];
int n, m, w, grupo = 0;

ll f( int pos, int sum) {
	if( pos == grupo ) return 0;
	if( done[ pos ][ sum ] ) return dp[ pos ][ sum ];
	done[ pos ][ sum ] = 1;
	ll ret = INF;
	ret = max( ret, f( pos + 1, sum ) );
	if( sum + Wa[ pos ] <= w ){
		ret = max( ret, Ba[ pos ] + f( pos+1, sum + Wa[ pos ] ) );
	}
	int sz = gp[ pos ].size();
	for( int i =0; i< sz; ++i ){
		if( sum + W[ gp[ pos ][ i ] ] <= w ){
			ret = max( ret, B[ gp[ pos ][ i ] ] + f( pos+1, W[ gp[ pos ][ i ] ] ) );
		}
	}

	dp[ pos ][ sum ] = ret;
	return ret;
}

void dfs( int u, int g ){
	if( vis[ u ] ) return;
	vis[ u ] = 1;
	G[ u ] = g;
	int sz = adj[ u ].size();
	for( int i=0; i<sz; ++i ){
		int v = adj[ u ][ i ];
		dfs( v, g );
	}
}

int main(){
	int x, y;
	scanf("%d%d%d", &n, &m, &w);
	for( int i=0; i<n; ++i ){
		scanf("%d", &W[ i ] );
	}
	for( int i=0; i<n; ++i ){
		scanf("%d", &B[ i ] );
	}
	for( int i=0; i<m; ++i ){
		scanf("%d%d", &x, &y );
		x--, y--;
		adj[ x ].pb( y );
		adj[ y ].pb( x );
	}
	for( int i=0; i<n; ++i ){
		if( !vis[ i ] ){
			dfs( i, grupo );
			grupo++;
		}
	}
	for( int i=0; i<n; ++i ){
		gp[ G[ i ] ].pb( i );
	}
	for( int i=0; i<grupo; ++i ){
		int sz = gp[ i ].size();
		//cout << sz <<endl;
		for( int j =0; j<sz; ++j ){
			//cout << " " << gp[ i ][ j ] <<endl;;
			Wa[ i ] += W[ gp[ i ][ j ] ];
			Ba[ i ] += B[ gp[ i ][ j ] ];
			//cout<< Wa[ i ] <<" " <<Ba[ i ] << endl;
		}
		//puts("");
	}
	for( int i=0; i<= n ; ++i )
		for( int j=0; j<= w ; ++j) done[ i ][ j ] = 0;

	cout << f( 0, 0 ) << endl;
}


#include<bits/stdc++.h>
#define N 1000
#define ll long long
#define pb push_back
#define INF -3000000000LL
using namespace std;

vector<int> adj[ N+5 ], gp[ N+5 ];
int W[ N+5 ], B[ N+5 ], G[ N+5 ], Ba[ N+5 ], Wa[ N+5 ];
bool vis[ N+5 ], done[ N+5 ][ N+5 ];
ll dp[ N+5 ][ N+5 ];
int n, m, w, grupo = 0;

ll f( int pos, int sum) {
	if( pos == grupo ) return 0;
	if( done[ pos ][ sum ] ) return dp[ pos ][ sum ];
	done[ pos ][ sum ] = 1;
	ll ret = INF;
	ret = max( ret, f( pos + 1, sum ) );
	if( sum + Wa[ pos ] <= w ){
		ret = max( ret, Ba[ pos ] + f( pos+1, sum + Wa[ pos ] ) );
	}
	int sz = gp[ pos ].size();
	for( int i =0; i< sz; ++i ){
		if( sum + W[ gp[ pos ][ i ] ] <= w ){
			ret = max( ret, B[ gp[ pos ][ i ] ] + f( pos+1, W[ gp[ pos ][ i ] ] ) );
		}
	}
	dp[ pos ][ sum ] = ret;
	return ret;
}

void dfs( int u, int g ){
	if( vis[ u ] ) return;
	vis[ u ] = 1;
	G[ u ] = g;
	int sz = adj[ u ].size();
	for( int i=0; i<sz; ++i ){
		int v = adj[ u ][ i ];
		dfs( v, g );
	}
}

int main(){
	int x, y;
	scanf("%d%d%d", &n, &m, &w);
	for( int i=0; i<n; ++i ){
		scanf("%d", &W[ i ] );
	}
	for( int i=0; i<n; ++i ){
		scanf("%d", &B[ i ] );
	}
	for( int i=0; i<m; ++i ){
		scanf("%d%d", &x, &y );
		x--, y--;
		adj[ x ].pb( y );
		adj[ y ].pb( x );
	}
	for( int i=0; i<n; ++i ){
		if( !vis[ i ] ){
			dfs( i, grupo );
			grupo++;
		}
	}
	for( int i=0; i<n; ++i ){
		gp[ G[ i ] ].pb( i );
	}
	for( int i=0; i<grupo; ++i ){
		int sz = gp[ i ].size();
		//cout << sz <<endl;
		for( int j =0; j<sz; ++j ){
			//cout << " " << gp[ i ][ j ] <<endl;;
			Wa[ i ] += W[ gp[ i ][ j ] ];
			Ba[ i ] += B[ gp[ i ][ j ] ];
			//cout<< Wa[ i ] <<" " <<Ba[ i ] << endl;
		}
		//puts("");
	}
	for( int i=0; i<= N ; ++i )
		for( int j=0; j<= N ; ++j) done[ i ][ j ] = 0;

	cout << f( 0, 0 ) << endl;
}


#include<bits/stdc++.h>
#define N 1000
#define ll long long
#define pb push_back
#define INF -3000000000LL
using namespace std;

vector<int> adj[ N+5 ], gp[ N+5 ];
int W[ N+5 ], B[ N+5 ], G[ N+5 ], Ba[ N+5 ], Wa[ N+5 ];
bool vis[ N+5 ], done[ N+5 ][ N+5 ];
ll dp[ N+5 ][ N+5 ];
int n, m, w, grupo = 0;

ll f( int pos, int sum) {
	if( pos == grupo ) return 0;
	if( done[ pos ][ sum ] ) return dp[ pos ][ sum ];
	done[ pos ][ sum ] = 1;
	ll ret = INF;
	ret = max( ret, f( pos + 1, sum ) );
	if( sum + Wa[ pos ] <= w ){
		ret = max( ret, Ba[ pos ] + f( pos+1, sum + Wa[ pos ] ) );
	}
	int sz = gp[ pos ].size();
	for( int i =0; i< sz; ++i ){
		if( sum + W[ gp[ pos ][ i ] ] <= w ){
			ret = max( ret, B[ gp[ pos ][ i ] ] + f( pos+1, sum + W[ gp[ pos ][ i ] ] ) );
		}
	}
	dp[ pos ][ sum ] = ret;
	return ret;
}

void dfs( int u, int g ){
	if( vis[ u ] ) return;
	vis[ u ] = 1;
	G[ u ] = g;
	int sz = adj[ u ].size();
	for( int i=0; i<sz; ++i ){
		int v = adj[ u ][ i ];
		dfs( v, g );
	}
}

int main(){
	int x, y;
	scanf("%d%d%d", &n, &m, &w);
	for( int i=0; i<n; ++i ){
		scanf("%d", &W[ i ] );
	}
	for( int i=0; i<n; ++i ){
		scanf("%d", &B[ i ] );
	}
	for( int i=0; i<m; ++i ){
		scanf("%d%d", &x, &y );
		x--, y--;
		adj[ x ].pb( y );
		adj[ y ].pb( x );
	}
	for( int i=0; i<n; ++i ){
		if( !vis[ i ] ){
			dfs( i, grupo );
			grupo++;
		}
	}
	for( int i=0; i<n; ++i ){
		gp[ G[ i ] ].pb( i );
	}
	for( int i=0; i<grupo; ++i ){
		int sz = gp[ i ].size();
		//cout << sz <<endl;
		for( int j =0; j<sz; ++j ){
			//cout << " " << gp[ i ][ j ] <<endl;;
			Wa[ i ] += W[ gp[ i ][ j ] ];
			Ba[ i ] += B[ gp[ i ][ j ] ];
			//cout<< Wa[ i ] <<" " <<Ba[ i ] << endl;
		}
		//puts("");
	}
	for( int i=0; i<= N ; ++i )
		for( int j=0; j<= N ; ++j) done[ i ][ j ] = 0;

	cout << f( 0, 0 ) << endl;
}


#include<bits/stdc++.h>
#define N 1000
#define ll long long
#define pb push_back
#define INF -3000000000
using namespace std;

vector<int> adj[ N+5 ], gp[ N+5 ];
int W[ N+5 ], B[ N+5 ], G[ N+5 ], Ba[ N+5 ], Wa[ N+5 ];
bool vis[ N+5 ], done[ N+5 ][ N+5 ];
ll dp[ N+5 ][ N+5 ];
int n, m, w, grupo = 0;

ll f( int pos, int sum) {
	if( pos == grupo ) return 0;
	if( done[ pos ][ sum ] ) return dp[ pos ][ sum ];
	done[ pos ][ sum ] = 1;
	ll ret = INF;
	ret = max( ret, f( pos + 1, sum ) );
	if( sum + Wa[ pos ] <= w ){
		ret = max( ret, Ba[ pos ] + f( pos+1, sum + Wa[ pos ] ) );
	}
	int sz = gp[ pos ].size();
	for( int i =0; i< sz; ++i ){
		if( sum + W[ gp[ pos ][ i ] ] <= w ){
			ret = max( ret, B[ gp[ pos ][ i ] ] + f( pos+1, W[ gp[ pos ][ i ] ] ) );
		}
	}
	dp[ pos ][ sum ] = ret;
	return ret;
}

void dfs( int u, int g ){
	if( vis[ u ] ) return;
	vis[ u ] = 1;
	G[ u ] = g;
	int sz = adj[ u ].size();
	for( int i=0; i<sz; ++i ){
		int v = adj[ u ][ i ];
		dfs( v, g );
	}
}

int main(){
	int x, y;
	scanf("%d%d%d", &n, &m, &w);
	for( int i=0; i<n; ++i ){
		scanf("%d", &W[ i ] );
	}
	for( int i=0; i<n; ++i ){
		scanf("%d", &B[ i ] );
	}
	for( int i=0; i<m; ++i ){
		scanf("%d%d", &x, &y );
		x--, y--;
		adj[ x ].pb( y );
		adj[ y ].pb( x );
	}
	for( int i=0; i<n; ++i ){
		if( !vis[ i ] ){
			dfs( i, grupo );
			grupo++;
		}
	}
	for( int i=0; i<n; ++i ){
		gp[ G[ i ] ].pb( i );
	}
	for( int i=0; i<grupo; ++i ){
		int sz = gp[ i ].size();
		//cout << sz <<endl;
		for( int j =0; j<sz; ++j ){
			//cout << " " << gp[ i ][ j ] <<endl;;
			Wa[ i ] += W[ gp[ i ][ j ] ];
			Ba[ i ] += B[ gp[ i ][ j ] ];
			//cout<< Wa[ i ] <<" " <<Ba[ i ] << endl;
		}
		//puts("");
	}
	for( int i=0; i<= N ; ++i )
		for( int j=0; j<= N ; ++j) done[ i ][ j ] = 0;

	cout << f( 0, 0 ) << endl;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#define ff first
#define ss second
using namespace std;

int wei[1111],bea[1111],par[1111];
bool is_gone[1111];
vector<int> edge[111111],grp[1111];
int dp[1111][1111];

void dfs(int p,int v){
    is_gone[v]=1;
    grp[p].push_back(v);
    for(int i=0;i<edge[v].size();i++){
        if(edge[v][i]!=par[v]){
            par[edge[v][i]]=v;
            dfs(p,edge[v][i]);
        }
    }
}

int main(){
    int n,m,w;

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    scanf("%d %d %d",&n,&m,&w);
    for(int i=1;i<=n;i++) scanf("%d",&wei[i]);
    for(int i=1;i<=n;i++) scanf("%d",&bea[i]);
    for(int i=1;i<=m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int pos=1;
    for(int i=1;i<=n;i++){
        if(!is_gone[i]) dfs(pos,i),pos++;
    }
/*
    for(int i=1;i<pos;i++){
        for(int j=0;j<grp[i].size();j++) printf("%d ",grp[i][j]);
        printf("\n");
    }
    printf("\n");
*/

    for(int i=0;i<pos;i++){
        for(int j=1;j<=w;j++) dp[i][j]=-1;
    }

    for(int i=0;i<pos-1;i++){
        for(int j=0;j<=w;j++){
            if(dp[i][j]!=-1){
                int sumw=0,sumb=0;

                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                for(int k=0;k<grp[i+1].size();k++){
                    sumw+=wei[grp[i+1][k]];
                    sumb+=bea[grp[i+1][k]];
                    if(j+wei[grp[i+1][k]]>w) continue;
                    dp[i+1][j+wei[grp[i+1][k]]]=max(dp[i+1][j+wei[grp[i+1][k]]],dp[i][j]+bea[grp[i+1][k]]);
                }
                if(j+sumw<=w) dp[i+1][j+sumw]=max(dp[i+1][j+sumw],dp[i][j]+sumb);
            }
        }
    }
/*
    printf("\n");
    for(int i=0;i<pos;i++){
        for(int j=0;j<=w;j++) printf("%8d",dp[i][j]);
        printf("\n");
    }
    printf("\n");
*/
    int mx=0;
    for(int i=0;i<=w;i++) mx=max(mx,dp[pos-1][i]);

    printf("%d",mx);

    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#define ff first
#define ss second
using namespace std;

int wei[1111],bea[1111],par[1111];
pair<int,int> hos[111111];
vector<int> grp[1111];
int dp[1111][1111];

int main(){
    int n,m,w;

    scanf("%d %d %d",&n,&m,&w);
    for(int i=1;i<=n;i++) scanf("%d",&wei[i]);
    for(int i=1;i<=n;i++) scanf("%d",&bea[i]);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&hos[i].ff,&hos[i].ss);
        if(hos[i].ff>hos[i].ss) swap(hos[i].ff,hos[i].ss);
    }
    sort(hos+1,hos+m+1);

    int pos=1;
    for(int i=1;i<=m;i++){
        if(!par[hos[i].ff]){
            par[hos[i].ff]=pos;
            grp[pos].push_back(hos[i].ff);
            pos++;
        }
        par[hos[i].ss]=par[hos[i].ff];
        grp[par[hos[i].ff]].push_back(hos[i].ss);
    }
    for(int i=1;i<=n;i++){
        if(!par[i]){
            par[i]=pos;
            grp[pos].push_back(i);
            pos++;
        }
    }
/*
    for(int i=1;i<pos;i++){
        for(int j=0;j<grp[i].size();j++) printf("%d ",grp[i][j]);
        printf("\n");
    }
    printf("\n");
    */

    for(int i=0;i<pos;i++){
        for(int j=1;j<=w;j++) dp[i][j]=-1;
    }

    for(int i=0;i<pos-1;i++){
        for(int j=0;j<=w;j++){
            if(dp[i][j]!=-1){
                int sumw=0,sumb=0;

                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                for(int k=0;k<grp[i+1].size();k++){
                    sumw+=wei[grp[i+1][k]];
                    sumb+=bea[grp[i+1][k]];
                    if(j+grp[i+1][k]>w) continue;
                    dp[i+1][j+grp[i+1][k]]=max(dp[i+1][j+grp[i+1][k]],dp[i][j]+bea[grp[i+1][k]]);
                }
                if(j+sumw<=w) dp[i+1][j+sumw]=max(dp[i+1][j+sumw],dp[i][j]+sumb);
            }
        }
    }

    int mx=0;
    for(int i=0;i<=w;i++) mx=max(mx,dp[pos-1][i]);

    printf("%d",mx);

    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#define ff first
#define ss second
using namespace std;

int wei[1111],bea[1111],par[1111];
pair<int,int> hos[111111];
vector<int> grp[1111];
int dp[1111][1111];

int main(){
    int n,m,w;

    scanf("%d %d %d",&n,&m,&w);
    for(int i=1;i<=n;i++) scanf("%d",&wei[i]);
    for(int i=1;i<=n;i++) scanf("%d",&bea[i]);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&hos[i].ff,&hos[i].ss);
        if(hos[i].ff>hos[i].ss) swap(hos[i].ff,hos[i].ss);
    }
    sort(hos+1,hos+m+1);

    int pos=1;
    for(int i=1;i<=m;i++){
        if(!par[hos[i].ff]){
            par[hos[i].ff]=pos;
            grp[pos].push_back(hos[i].ff);
            pos++;
        }
        par[hos[i].ss]=par[hos[i].ff];
        grp[par[hos[i].ff]].push_back(hos[i].ss);
    }
    for(int i=1;i<=n;i++){
        if(!par[i]){
            par[i]=pos;
            grp[pos].push_back(i);
            pos++;
        }
    }
/*
    for(int i=1;i<pos;i++){
        for(int j=0;j<grp[i].size();j++) printf("%d ",grp[i][j]);
        printf("\n");
    }
    printf("\n");
    */

    for(int i=0;i<pos;i++){
        for(int j=1;j<=w;j++) dp[i][j]=-1;
    }

    for(int i=0;i<pos-1;i++){
        for(int j=0;j<=w;j++){
            if(dp[i][j]!=-1){
                int sumw=0,sumb=0;

                dp[i+1][j]=dp[i][j];
                for(int k=0;k<grp[i+1].size();k++){
                    sumw+=wei[grp[i+1][k]];
                    sumb+=bea[grp[i+1][k]];
                    if(j+grp[i+1][k]>w) continue;
                    dp[i+1][j+grp[i+1][k]]=max(dp[i+1][j+grp[i+1][k]],dp[i][j]+bea[grp[i+1][k]]);
                }
                if(j+sumw<=w) dp[i+1][j+sumw]=max(dp[i+1][j+sumw],dp[i][j]+sumb);
            }
        }
    }

    int mx=0;
    for(int i=0;i<=w;i++) mx=max(mx,dp[pos-1][i]);

    printf("%d",mx);

    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#define ff first
#define ss second
using namespace std;

int wei[1111],bea[1111];
bool is_gone[1111];
vector<int> edge[1111],grp[1111];
int dp[1111][1111];

void dfs(int p,int v){
    is_gone[v]=1;
    grp[p].push_back(v);
    for(int i=0;i<edge[v].size();i++){
        if(!is_gone[edge[v][i]]) dfs(p,edge[v][i]);
    }
}

int main(){
    int n,m,w;

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    scanf("%d %d %d",&n,&m,&w);
    for(int i=1;i<=n;i++) scanf("%d",&wei[i]);
    for(int i=1;i<=n;i++) scanf("%d",&bea[i]);
    for(int i=1;i<=m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int pos=1;
    for(int i=1;i<=n;i++){
        if(!is_gone[i]) dfs(pos,i),pos++;
    }
/*
    for(int i=1;i<pos;i++){
        for(int j=0;j<grp[i].size();j++) printf("%d ",grp[i][j]);
        printf("\n");
    }
    printf("\n");
*/

    for(int i=0;i<pos;i++){
        for(int j=1;j<=w;j++) dp[i][j]=-1;
    }

    for(int i=0;i<pos-1;i++){
        for(int j=0;j<=w;j++){
            if(dp[i][j]!=-1){
                int sumw=0,sumb=0;

                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                for(int k=0;k<grp[i+1].size();k++){
                    sumw+=wei[grp[i+1][k]];
                    sumb+=bea[grp[i+1][k]];
                    if(j+wei[grp[i+1][k]]>w) continue;
                    dp[i+1][j+wei[grp[i+1][k]]]=max(dp[i+1][j+wei[grp[i+1][k]]],dp[i][j]+bea[grp[i+1][k]]);
                }
                if(j+sumw<=w) dp[i+1][j+sumw]=max(dp[i+1][j+sumw],dp[i][j]+sumb);
            }
        }
    }
/*
    printf("\n");
    for(int i=0;i<pos;i++){
        for(int j=0;j<=w;j++) printf("%8d",dp[i][j]);
        printf("\n");
    }
    printf("\n");
*/
    int mx=0;
    for(int i=0;i<=w;i++) mx=max(mx,dp[pos-1][i]);

    printf("%d",mx);

    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#define ff first
#define ss second
using namespace std;

int wei[1111],bea[1111],par[1111];
pair<int,int> hos[111111];
vector<int> grp[1111];
int dp[1111][1111];

int main(){
    int n,m,w;

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    scanf("%d %d %d",&n,&m,&w);
    for(int i=1;i<=n;i++) scanf("%d",&wei[i]);
    for(int i=1;i<=n;i++) scanf("%d",&bea[i]);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&hos[i].ff,&hos[i].ss);
        if(hos[i].ff>hos[i].ss) swap(hos[i].ff,hos[i].ss);
    }
    sort(hos+1,hos+m+1);

    int pos=1;
    for(int i=1;i<=m;i++){
        if(!par[hos[i].ff]){
            par[hos[i].ff]=pos;
            grp[pos].push_back(hos[i].ff);
            pos++;
        }
        if(!par[hos[i].ss]){
            par[hos[i].ss]=par[hos[i].ff];
            grp[par[hos[i].ff]].push_back(hos[i].ss);
        }
    }
    for(int i=1;i<=n;i++){
        if(!par[i]){
            par[i]=pos;
            grp[pos].push_back(i);
            pos++;
        }
    }
/*
    for(int i=1;i<pos;i++){
        for(int j=0;j<grp[i].size();j++) printf("%d ",grp[i][j]);
        printf("\n");
    }
    printf("\n");
*/

    for(int i=0;i<pos;i++){
        for(int j=1;j<=w;j++) dp[i][j]=-1;
    }

    for(int i=0;i<pos-1;i++){
        for(int j=0;j<=w;j++){
            if(dp[i][j]!=-1){
                int sumw=0,sumb=0;

                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                for(int k=0;k<grp[i+1].size();k++){
                    sumw+=wei[grp[i+1][k]];
                    sumb+=bea[grp[i+1][k]];
                    if(j+wei[grp[i+1][k]]>w) continue;
                    dp[i+1][j+wei[grp[i+1][k]]]=max(dp[i+1][j+wei[grp[i+1][k]]],dp[i][j]+bea[grp[i+1][k]]);
                }
                if(j+sumw<=w) dp[i+1][j+sumw]=max(dp[i+1][j+sumw],dp[i][j]+sumb);
            }
        }
    }
/*
    printf("\n");
    for(int i=0;i<pos;i++){
        for(int j=0;j<=w;j++) printf("%8d",dp[i][j]);
        printf("\n");
    }
    printf("\n");
*/
    int mx=0;
    for(int i=0;i<=w;i++) mx=max(mx,dp[pos-1][i]);

    printf("%d",mx);

    return 0;
}


# include <bits/stdc++.h>
# define IoS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  using namespace std;
  long long k, s, b, ans, W;
  long long arr[1010], brr[1010];
  int color[1010];
  vector< int > vrr[1010];
  vector< pair< int, int > > res;
  inline void way(int v)
  {
      color[v] = 1;
      s += arr[v];
      b += brr[v];
      for(int i = 0; i <= k; i++){
        if(res[i].first + arr[v] <= W){
            res.push_back({res[i].first + arr[v], res[i].second + brr[v]});
            ans = max(ans, res[i].second + brr[v]);
        }
      }
      for(int x : vrr[v]){
        if(color[x] == 0) way(x);
      }
  }
  int main()
  {
      IoS;
      long long n, m, i, x, y, j;
      cin >> n >> m >> W;
      for(i = 1; i <= n; i++){
        cin >> arr[i];
      }
      for(i = 1; i <= n; i++){
        cin >> brr[i];
      }
      for(i = 1; i <= m; i++){
        cin >> x >> y;
        vrr[x].push_back(y);
        vrr[y].push_back(x);
      }
      res.push_back({0, 0});
      for(i = 1; i <= n; i++){
        if(color[i] == 0){
            s = 0;
            b = 0;
            k = res.size() - 1;
            way(i);
            for(j = 0; j <= k; j++){
                if(res[j].first + s <= W){
                    ans = max(ans, res[j].second + b);
                    res.push_back({res[j].first + s, res[j].second + b});
                }
            }
        }
      }
      cout << ans;
      return 0;
  }
/**
*/


# include <bits/stdc++.h>
# define IoS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  using namespace std;
  long long k, s, b, ans, W;
  long long arr[1010], brr[1010], dp[1010];
  int color[1010];
  vector< int > vrr[1010];
  vector< int > res;
  inline void way(int v)
  {
      color[v] = 1;
      s += arr[v];
      b += brr[v];
      for(int i = 0; i <= k; i++){
        if(res[i] + arr[v] <= W){
            if(dp[res[i] + arr[v]] == 0) res.push_back(res[i] + arr[v]);
            dp[res[i] + arr[v]] = max(dp[res[i] + arr[v]], dp[res[i]] + brr[v]);
            ans = max(ans, dp[res[i]] + brr[v]);
        }
      }
      for(int x : vrr[v]){
        if(color[x] == 0) way(x);
      }
  }
  int main()
  {
      IoS;
      long long n, m, i, x, y, j;
      cin >> n >> m >> W;
      for(i = 1; i <= n; i++){
        cin >> arr[i];
      }
      for(i = 1; i <= n; i++){
        cin >> brr[i];
      }
      for(i = 1; i <= m; i++){
        cin >> x >> y;
        vrr[x].push_back(y);
        vrr[y].push_back(x);
      }
      res.push_back(0);
      for(i = 1; i <= n; i++){
        if(color[i] == 0){
            s = 0;
            b = 0;
            k = res.size() - 1;
            way(i);
            for(j = 0; j <= k; j++){
                if(res[j] + s <= W){
                    ans = max(ans, dp[res[j]] + b);
                    if(dp[res[j] + s] == 0) res.push_back(res[j] + s);
                    dp[res[j] + s] = max(dp[res[j] + s], b + dp[res[j]]);
                }
            }
        }
      }
      cout << ans;
      return 0;
  }
/**
*/


# include <bits/stdc++.h>
# define IoS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  using namespace std;
  long long k, s, b, ans, W;
  long long arr[1010], brr[1010];
  int color[1010];
  vector< int > vrr[1010];
  vector< pair< long long, long long > > res;
  inline void way(int v)
  {
      color[v] = 1;
      s += arr[v];
      b += brr[v];
      for(int i = 0; i <= k; i++){
        if(res[i].first + arr[v] <= W){
            res.push_back({res[i].first + arr[v], res[i].second + brr[v]});
            ans = max(ans, res[i].second + brr[v]);
        }
      }
      for(int x : vrr[v]){
        if(color[x] == 0) way(x);
      }
  }
  int main()
  {
      IoS;
      long long n, m, i, x, y, j;
      cin >> n >> m >> W;
      for(i = 1; i <= n; i++){
        cin >> arr[i];
      }
      for(i = 1; i <= n; i++){
        cin >> brr[i];
      }
      for(i = 1; i <= m; i++){
        cin >> x >> y;
        vrr[x].push_back(y);
        vrr[y].push_back(x);
      }
      res.push_back({0, 0});
      for(i = 1; i <= n; i++){
        if(color[i] == 0){
            s = 0;
            b = 0;
            k = res.size() - 1;
            way(i);
            for(j = 0; j <= k; j++){
                if(res[j].first + s <= W){
                    ans = max(ans, res[j].second + b);
                    res.push_back({res[j].first + s, res[j].second + b});
                }
            }
        }
      }
      cout << ans;
      return 0;
  }
/**
*/


# include <bits/stdc++.h>
# define IoS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  using namespace std;
  long long n;
  long long arr[1010], brr[1010], dp[1010];
  int color[1010];
  vector< int > vrr[1010];
  vector< int > res;
  inline void way(int v)
  {
      color[v] = 1;
      arr[n + 1] += arr[v];
      brr[n + 1] += brr[v];
      res.push_back(v);
      for(int x : vrr[v]){
        if(color[x] == 0) way(x);
      }
  }
  int main()
  {
      IoS;
      long long m, i, x, y, W, ans, j;
      cin >> n >> m >> W;
      for(i = 1; i <= n; i++){
        cin >> arr[i];
      }
      for(i = 1; i <= n; i++){
        cin >> brr[i];
      }
      for(i = 1; i <= m; i++){
        cin >> x >> y;
        vrr[x].push_back(y);
        vrr[y].push_back(x);
      }
      ans = 0;
      for(i = 1; i <= n; i++){
        if(color[i] == 0){
            arr[n + 1] = brr[n + 1] = 0;
            res.clear();
            way(i);
            res.push_back(n + 1);
            for(j = W; j >= 0; j--){
                for(y = 0; y < res.size(); y++){
                    if((j + arr[res[y]] <= W) && ((j == 0) || (dp[j] > 0))){
                        dp[j + arr[res[y]]] = max(dp[j + arr[res[y]]], dp[j] + brr[res[y]]);
                        ans = max(ans, dp[j + arr[res[y]]]);
                    }
                }
            }
        }
      }
      cout << ans;
      return 0;
  }
/**
*/


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i <= items.size(); i++) {
		for(int j = 0; j <= w; j++) {
			for(int k = 0; k < items[i - 1].size(); k++) {
				if(ws[items[i - 1][k]] <= j)
					dp[i][j] = max({dp[i - 1][j], dp[i][j], dp[i - 1][j - ws[items[i - 1][k]]] + bs[items[i - 1][k]]});
			}
		}
	}

	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i < items.size() + 1; i++) {
		for(int j = 0; j <= w; j++) {
			for(int k = 0; k < items[i - 1].size(); k++) {
				if(ws[items[i - 1][k]] <= j)
					dp[i][j] = max(dp[i][j], dp[i - 1][j - ws[items[i - 1][k]]] + bs[items[i - 1][k]]);
			}
		}
	}

// 	for(auto x : items) {
// 		for(auto y : x) cout << y << ' ';
// 		cout << endl;
// 	}

// 	for(int i = 0; i <= items.size(); i++) {
// 		for(int j = 0; j < w + 1; j++) {
// 			cout << dp[i][j] << ' ';
// 		}
// 		cout << endl;
// 	}
	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i <= items.size(); i++) {
		for(int j = 0; j <= w; j++) {
			for(int k = 0; k < items[i - 1].size(); k++) {
				if(ws[items[i - 1][k]] <= j)
					dp[i][j] = max(dp[i][j], dp[i - 1][j - ws[items[i - 1][k]]] + bs[items[i - 1][k]]);
			}
		}
	}

	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i < items.size() + 1; i++) {
		for(int j = 0; j <= w; j++) {
			for(int k = 0; k < items[i - 1].size(); k++) {
				if(ws[items[i - 1][k]] <= j)
					dp[i][j] = max(dp[i - 1][j], max(dp[i][j], dp[i - 1][j - ws[items[i - 1][k]]] + bs[items[i - 1][k]]));
			}
		}
	}

// 	for(auto x : items) {
// 		for(auto y : x) cout << y << ' ';
// 		cout << endl;
// 	}

// 	for(int i = 0; i <= items.size(); i++) {
// 		for(int j = 0; j < w + 1; j++) {
// 			cout << dp[i][j] << ' ';
// 		}
// 		cout << endl;
// 	}
	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i < items.size() + 1; i++) {
		for(int j = 0; j <= w; j++) {
			for(int k = 0; k < items[i - 1].size(); k++) {
				if(ws[items[i - 1][k]] <= j)
					dp[i][j] = max(dp[i][j], dp[i - 1][j - ws[items[i - 1][k]]] + bs[items[i - 1][k]]);
			}
		}
	}

	for(auto x : items) {
		for(auto y : x) cout << y << ' ';
		cout << endl;
	}

	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}
	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 1001;

vector<vector<int> > items;
vector<int> tmp;
vector<int> g[maxn];
bool was[maxn];

void dfs(int v) {
	tmp.push_back(v);
	was[v] = 1;
	for(int x : g[v]) {
		if(!was[x]) dfs(x);
	}
}

int main() {
	int n, m, w;
	cin >> n >> m >> w;
	int ws[2 * n], bs[2 * n];
	for(int i = 0; i < n; i++) {
		cin >> ws[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> bs[i];
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(was, was + n, 0);
	int q = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
			dfs(i);
			int neww = 0, newb = 0;
			for(int x : tmp) neww += ws[x], newb += bs[x];
			ws[n + q] = neww;
			bs[n + q] = newb;
			tmp.push_back(n + q);
			q++;
			items.push_back(tmp);
			tmp.clear();
		}
	}
	int dp[items.size() + 1][w + 1];
	for(int i = 0; i <= items.size(); i++) {
		for(int j = 0; j < w + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 1; i <= items.size(); i++) {
		for(int j = 0; j <= w; j++) {
			for(int k : items[i - 1]) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
				if(ws[k] <= j)
					dp[i][j] = max(dp[i][j], dp[i - 1][j - ws[k]] + bs[k]);
			}
		}
	}
	// for(int i = 0; i <= items.size(); i++) {
	// 	for(int j = 0; j <= w; j++) {
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << endl;
	// }
	cout << dp[items.size()][w] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1005];
int weight[1005],beauty[1005],dp[3003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
queue<int> q;

void bfs(int xx,int t)
{
	int sW=0,sB=0,x;
	while(!q.empty())
		q.pop();
	q.push(xx);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=0;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	if(m==100000)
	{
		cout<<g.size()<<endl;
		return 0;
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1002];
int weight[1002],beauty[1002],dp[6003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
void bfs(int x,int t)
{
	int sW=0,sB=0;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=1;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1005];
int weight[1005],beauty[1005],dp[3003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
queue<int> q;

void bfs(int xx,int t)
{
	int sW=0,sB=0,x;
	while(!q.empty())
		q.pop();
	q.push(xx);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
			{
				visit[g[x][i]]=true;
				q.push(g[x][i]);
			}
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=0;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	if(m==100000)
	{
		cout<<g.size()<<" "<<posT.size()<<" "<<B.size()<<endl;
		return 0;
	}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1005];
int weight[1005],beauty[1005],dp[3003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
queue<int> q;

void bfs(int xx,int t)
{
	int sW=0,sB=0,x;
	while(!q.empty())
		q.pop();
	q.push(xx);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
			{
				visit[g[x][i]]=true;
				q.push(g[x][i]);
			}
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=0;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	/*if(m==100000)
	{
		cout<<g.size()<<" "<<posT.size()<<" "<<B.size()<<endl;
		return 0;
	}*/
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[2002];
int weight[2002],beauty[2002],dp[3003][2002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
void bfs(int x,int t)
{
	int sW=0,sB=0;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=1;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1002];
int weight[1002],beauty[1002],dp[3003][2002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
void bfs(int x,int t)
{
	int sW=0,sB=0;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=1;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1002];
int weight[1002],beauty[1002],dp[2003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
void bfs(int x,int t)
{
	int sW=0,sB=0;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=1;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1005];
int weight[1005],beauty[1005],dp[3003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
queue<int> q;

void bfs(int xx,int t)
{
	int sW=0,sB=0,x;
	while(!q.empty())
		q.pop();
	q.push(xx);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=0;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	if(m==100000)
	{
		cout<<g.size()<<" "<<posT.size()<<" "<<B.size()<<endl;
		return 0;
	}
	cout<<knapsack()<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,w,tot;
bool visit[1005];
int weight[1005],beauty[1005],dp[3003][1002];
vector<int> W,B,T;
vector<vector<int> > g;
vector<pair<int,int> > posT;
queue<int> q;

void bfs(int xx,int t)
{
	int sW=0,sB=0,x;
	while(!q.empty())
		q.pop();
	q.push(xx);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sW+=weight[x];
		sB+=beauty[x];
		W.push_back(weight[x]);
		B.push_back(beauty[x]);
		T.push_back(t);
		visit[x]=true;
		for(int i=0;i<g[x].size();i++)
			if(!visit[g[x][i]])
				q.push(g[x][i]);
	}
	W.push_back(sW);
	B.push_back(sB);
	T.push_back(t);
}
int knapsack()
{
	for(int i=0;i<=w;i++)
		for(int j=0;j<=B.size();j++)
			dp[j][i]=0;
	for(int i=1;i<tot;i++)
	{
		for(int k=posT[i].first;k<=posT[i].second;k++)
		{
			for(int j=posT[i-1].first;j<=posT[i-1].second;j++)
			{
				for(int x=0;x<=w;x++)
					if(x-W[k]>=0)
						dp[k][x]=max(dp[k][x],max(dp[j][x],dp[j][x-W[k]]+B[k]));
					else
						dp[k][x]=max(dp[k][x],dp[j][x]);
			}
		}
	}
	int ans=0;
	for(int i=posT[tot-1].first;i<=posT[tot-1].second;i++)
		ans=max(ans,dp[i][w]);
	return ans;
}
int main()
{
	int a,b,l,r;
	cin>>n>>m>>w;
	g=vector<vector<int> >(n+1);
	for(int i=1;i<=n;i++)
		cin>>weight[i];
	for(int i=1;i<=n;i++)
		cin>>beauty[i];
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(visit,false,sizeof visit);
	W.push_back(0); B.push_back(0); T.push_back(0);
	posT.push_back(make_pair(0,0)); tot=1;
	for(int i=1;i<=n;i++)
		if(!visit[i])
		{
			l=W.size();
			bfs(i,tot);
			posT.push_back(make_pair(l,W.size()-1));
			tot++;
		}
	cout<<knapsack()<<endl;
	return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e3 + 9;

vvi gg;
vpii group[MAXN];
int ww[MAXN], dp[2 * MAXN][MAXN], bb[MAXN];
bool used[MAXN];
int n, m, w;
pii cur;
int cnt = 0;

void dfs(int v) {
	used[v] = 1;
	cur.first += ww[v];
	cur.second += bb[v];
	group[cnt].pb({ ww[v], bb[v] });
	for(int i = 0; i < sz(gg[v]); i++) {
		int to = gg[v][i];
		if(!used[to]) dfs(to);
	}
}

void input() {
	cin >> n >> m >> w;
	for(int i = 0; i < n; i++) cin >> ww[i];
	for(int i = 0; i < n; i++) cin >> bb[i];
	gg.resize(n);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gg[u].pb(v);
		gg[v].pb(u);
	}
}

void solve() {
	cnt = 1;
	for(int i = 0; i < n; i++) {
		if(!used[i]) {
			cur = {0, 0};
			dfs(i);
			if(sz(gg[i]) != 0) group[cnt].pb(cur);
			cnt++;
		}
	}
	for(int j = 1; j <= w; j++) {
		for(int i = 1; i < cnt; i++) {
			dp[i][j] = dp[i - 1][j];
			for(int k = 0; k < sz(group[i]); k++) {
				if(j < group[i][k].first) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][j - group[i][k].first] + group[i][k].second);
			}
		}
	}
	cout << dp[cnt - 1][w] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif
	input();
	solve();
	return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e3 + 9;

vvi gg;
vpii group[MAXN];
vpii gw;
int ww[MAXN], dp[2 * MAXN][MAXN], bb[MAXN];
bool used[MAXN];
int n, m, w;
pii cur;
int cnt = 0;

void dfs(int v) {
	used[v] = 1;
	cur.first += ww[v];
	cur.second += bb[v];
	group[cnt].pb({ ww[v], bb[v] });
	for(int i = 0; i < sz(gg[v]); i++) {
		int to = gg[v][i];
		if(!used[to]) dfs(to);
	}
}

void input() {
	cin >> n >> m >> w;
	for(int i = 0; i < n; i++) cin >> ww[i];
	for(int i = 0; i < n; i++) cin >> bb[i];
	gg.resize(n);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gg[u].pb(v);
		gg[v].pb(u);
	}
}

void solve() {
	for(int i = 0; i < n; i++) {
		if(!used[i]) {
			cur = {0, 0};
			dfs(i);
			//cout << i << " : " << sz(gg[i]) << endl;
			if(sz(gg[i]) != 0) group[cnt].pb(cur);
			cnt++;
		}
	}
	//cout << cnt << '\n';
	//for(int i = 0; i < sz(gw); i++) cout << i << " : " << gw[i].first << ' ' << gw[i].second << '\n';
	for(int j = 1; j <= w; j++) {
		for(int i = 0; i < cnt; i++) {
			if(i == 0) dp[i][j] = 0;
			else dp[i][j] = dp[i - 1][j];
			for(int k = 0; k < sz(group[i]); k++) {
				if(j < group[i][k].first) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][j - group[i][k].first] + group[i][k].second);
			}
		}
	}
	/*for(int i = 0; i < cnt; i++) {
		for(int j = 1; j <= w; j++) {
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}*/
	cout << dp[cnt - 1][w] << '\n';
}

int main() {
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif
	input();
	solve();
	return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e3 + 9;

vvi gg;
vpii group[MAXN];
int ww[MAXN], dp[2 * MAXN][MAXN], bb[MAXN];
bool used[MAXN];
int n, m, w;
pii cur;
int cnt = 0;

void dfs(int v) {
	used[v] = 1;
	cur.first += ww[v];
	cur.second += bb[v];
	group[cnt].pb({ ww[v], bb[v] });
	for(int i = 0; i < sz(gg[v]); i++) {
		int to = gg[v][i];
		if(!used[to]) dfs(to);
	}
}

void input() {
	cin >> n >> m >> w;
	for(int i = 0; i < n; i++) cin >> ww[i];
	for(int i = 0; i < n; i++) cin >> bb[i];
	gg.resize(n);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gg[u].pb(v);
		gg[v].pb(u);
	}
}

void solve() {
	cnt = 1;
	for(int i = 0; i < n; i++) {
		if(!used[i]) {
			cur = {0, 0};
			dfs(i);
			if(sz(gg[i]) != 0) group[cnt].pb(cur);
			cnt++;
		}
	}
	//cout << cnt << '\n';
	//for(int i = 0; i < sz(gw); i++) cout << i << " : " << gw[i].first << ' ' << gw[i].second << '\n';
	for(int j = 1; j <= w; j++) {
		for(int i = 0; i < cnt; i++) {
			if(i == 0) dp[i][j] = 0;
			else dp[i][j] = dp[i - 1][j];
			for(int k = 0; k < sz(group[i]); k++) {
				if(j < group[i][k].first) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][j - group[i][k].first] + group[i][k].second);
			}
		}
	}
	/*for(int i = 0; i < cnt; i++) {
		for(int j = 1; j <= w; j++) {
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}*/
	cout << dp[cnt - 1][w] << '\n';
}

int main() {
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif
	input();
	solve();
	return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e3 + 9;

vvi gg;
vpii group[MAXN];
int ww[MAXN], dp[2 * MAXN][MAXN], bb[MAXN];
bool used[MAXN];
int n, m, w;
pii cur;
int cnt = 0;

void dfs(int v) {
	used[v] = 1;
	cur.first += ww[v];
	cur.second += bb[v];
	group[cnt].pb({ ww[v], bb[v] });
	for(int i = 0; i < sz(gg[v]); i++) {
		int to = gg[v][i];
		if(!used[to]) dfs(to);
	}
}

void input() {
	cin >> n >> m >> w;
	for(int i = 0; i < n; i++) cin >> ww[i];
	for(int i = 0; i < n; i++) cin >> bb[i];
	gg.resize(n);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gg[u].pb(v);
		gg[v].pb(u);
	}
}

void solve() {
	cnt = 1;
	for(int i = 0; i < n; i++) {
		if(!used[i]) {
			cur = {0, 0};
			dfs(i);
			if(sz(gg[i]) != 0) group[cnt].pb(cur);
			cnt++;
		}
	}
	for(int j = 1; j <= w; j++) {
		for(int i = 0; i < cnt; i++) {
			if(i == 0) dp[i][j] = 0;
			else dp[i][j] = dp[i - 1][j];
			for(int k = 0; k < sz(group[i]); k++) {
				if(j < group[i][k].first) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][j - group[i][k].first] + group[i][k].second);
			}
		}
	}
	cout << dp[cnt - 1][w] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif
	input();
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        /*
        if(a > b);
            swap(a, b);
        */
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int ans;
    if(rec[n].fa != n)
    {
        ans = findfather(rec[n].fa);
    }
    else
        return n;
    rec[n].fa = ans;
    return ans;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);

        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b)
            swap(a, b);
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(int ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    while(rec[n].fa != n)
    {
        n = rec[n].fa;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);

        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int ans;
    if(rec[n].fa != n)
    {
        ans = findfather(rec[n].fa);
    }
    else
        return n;
    rec[n].fa = ans;
    return ans;
}

void add(int a, int b)
{
    int af = findfather(a);
    int bf = findfather(b);
    if(af != bf)
        rec[bf].fa = af;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);
        add(a, b);
        //rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>
using namespace std;
vector<int>G[1005];
int n, m, w;
bool vis[1005];
int dp[1005];
int val[2005], weg[2005];
int par[1005], Rank[1005];
void init(int n)
{
    for(int i = 1;i <= n;i++){
        G[i].clear();
        par[i] = i;
        Rank[i] = 0;
    }
}
int Find(int x){
    if(par[x] == x) return x;
    else return par[x] = Find(par[x]);
}
int main()
{
    int i;
    scanf("%d %d %d", &n, &m, &w);
    for(i = 1;i <= n;i++) scanf("%d", &weg[i]);
    for(i = 1;i <= n;i++) scanf("%d", &val[i]);
    init(n);
    int u, v, j, k;
    for(i = 0;i < m;i++){
        scanf("%d %d", &u, &v);
        int f1, f2;
        f1 = Find(u), f2 = Find(v);
        if(f1==f2) continue;
        if(Rank[u]<Rank[v]) par[u] = v;
        else {
            par[v] = u;
            if(Rank[u]==Rank[v]) Rank[u]++;
        }
    }
    int p = n;
    for(i = 1;i <= n;i++){
        if(vis[i]) continue;
        vis[i] = 1;
        //printf("%d -\n", i);
        int f1 = Find(i);
        G[i].push_back(i);
        int sumw = 0, sumv = 0;
        for(j = 1;j <= n;j++){
            if(vis[j]) continue;
            if(f1==Find(j)){
                sumw += weg[j];
                sumv += val[j];
                vis[j] = 1;
                G[i].push_back(j);
                //printf("%d %d\n", i, j);
            }
        }
        if(sumw != 0) {
            sumw += weg[i];
            sumv += val[i];
            p++;
            G[i].push_back(p);
            weg[p] = sumw;
            val[p] = sumv;
        }
    }
    for(i = 1;i <= n;i++){
        if(G[i].size()==0) continue;
        for(j = w;j >= 0;j--){
            for(k = 0;k < G[i].size();k++){
                int u = G[i][k];
                if(weg[u]>j) continue;
                dp[j] = max(dp[j], dp[j-weg[u]]+val[u]);
            }
        }
    }
    printf("%d\n", dp[w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b)
            swap(a, b);
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int ans;
    if(rec[n].fa != n)
    {
        ans = findfather(rec[n].fa);
    }
    else
        return n;
    rec[n].fa = ans;
    return ans;
}

void add(int a, int b)
{
    int af = findfather(a);
    int bf = findfather(b);
    if(af != bf)
        rec[bf].fa = af;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);
        add(a, b);
        //rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }

    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    for(int i = 1; i <= gnum; i++)
    {
        for(int j = w; j > 0; j--)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b);
            swap(a, b);
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(int ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

void add(int a, int b)
{
    while(rec[a].fa != a)
    {
        a = rec[a].fa;
    }
    rec[a].fa = b;
}

int findfather(int n)
{
    int ans;
    if(rec[n].fa != n)
    {
        ans = findfather(rec[n].fa);
    }
    else
        return n;
    rec[n].fa = ans;
    return ans;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);
        add(a, b);
        //rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b);
            swap(a, b);
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(int ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int fa;
    while(rec[n].fa != n)
    {
        fa = n;
        n = rec[n].fa;
        rec[fa].fa = n;
    }
    return n;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int fmax(int a, int b)
{
    if(a > b)
        return a;
    else
        return b;
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b);
            swap(a, b);
        rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("%d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa);
    }
    */
    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    int pos1 = 1;
    int ii;
    for(int ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = fmax(dp[1][ii - 1], rec[pos1].b);
            pos1++;
            while(rec[pos1].w == rec[pos1 - 1].w)
                pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 2; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int temp = rec[pos1].go;
            dp[i][j] = fmax(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                if(j >= rec[k].w)
                    dp[i][j] = fmax(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
        }
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <bits/stdc++.h>

using namespace std;

struct hose
{
    int w, b, no, fa, go;
};

hose rec[2005];

int dp[2005][2005];

int findfather(int n)
{
    int ans;
    if(rec[n].fa != n)
    {
        ans = findfather(rec[n].fa);
    }
    else
        return n;
    rec[n].fa = ans;
    return ans;
}

void add(int a, int b)
{
    int af = findfather(a);
    int bf = findfather(b);
    if(af != bf)
        rec[bf].fa = af;
}

bool cmpfa(hose a, hose b)
{
    return a.fa < b.fa;
}

bool cmpfa2(hose a, hose b)
{
    if(a.fa != b.fa)
        return a.fa < b.fa;
    else
    {
        if(a.w != b.w)
            return a.w < b.w;
        else
            return a.b > b.b;
    }
}

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    int n, m, w;
    scanf("%d%d%d", &n, &m, &w);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].w);
        rec[i].no = i;
        rec[i].fa = i;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &rec[i].b);
    }
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);

        if(a > b);
            swap(a, b);
        add(a, b);
        //rec[b].fa = a;
    }
    for(int i = 1; i <= n; i++)
    {
        rec[i].fa = findfather(i);
    }
    //printf("Done\n");
    sort(rec + 1, rec + n + 1, cmpfa);
    int gnum = 1;
    rec[n + 1].w = rec[1].w;
    rec[n + 1].b = rec[1].b;
    rec[n + 1].fa = rec[1].fa;
    for(int i = 2; i <= n; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
        {
            gnum++;
            rec[n + gnum].w = rec[i].w;
            rec[n + gnum].b = rec[i].b;
            rec[n + gnum].fa = rec[i].fa;
        }
        else
        {
            rec[n + gnum].w += rec[i].w;
            rec[n + gnum].b += rec[i].b;
        }
    }

    sort(rec + 1, rec + n + gnum + 1, cmpfa2);
    rec[1].go = 1;
    for(int i = 2; i <= n + gnum; i++)
    {
        if(rec[i].fa != rec[i - 1].fa)
            rec[i].go = rec[i - 1].go + 1;
        else
            rec[i].go = rec[i - 1].go;
    }
    /*
    for(int i = 1; i <= n + gnum; i++)
    {
        printf("base==%d %d %d %d %d\n", rec[i].w, rec[i].b, rec[i].no, rec[i].fa, rec[i].go);
    }
    */
    int pos1 = 1;
    /*
    int ii;
    for(ii = 1; ; ii++)
    {
        if(ii < rec[pos1].w)
        {
            dp[1][ii] = dp[1][ii - 1];
        }
        else
        {
            dp[1][ii] = max(dp[1][ii - 1], rec[pos1].b);
            pos1++;
        }
        if(rec[pos1].go != 1)
            break;
    }
    ii++;
    for(; ii <= w; ii++)
    {
        dp[1][ii] = dp[1][ii - 1];
    }
    */
    /*
    for(int i = 1; i <= w; i++)
    {
        printf("%d ", dp[1][i]);
    }
    printf("\n");
    */
    for(int i = 1; i <= gnum; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            //printf("pos%d ", pos1);
            int temp = rec[pos1].go;
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            for(int k = pos1; rec[k].go == temp; k++)
            {
                //printf("k%d %d ", k, rec[k].go);
                if(j >= rec[k].w)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - rec[k].w] + rec[k].b);
            }
            //printf("\n");
            //printf("%d ", dp[i][j]);
        }
        //printf("\n");
        while(rec[pos1].go == rec[pos1 + 1].go)
            pos1++;
        pos1++;
    }
    printf("%d\n", dp[gnum][w]);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <iterator>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n,m,W,k,schw,schc;
int a[2000],b[2000];
bool b1[2000];
int dp[2000][2000];
vector<vector<int> > g,ans(1);
vector<pair<int,int> > sum(1);

void dfs(int x)
{
    ans[k].push_back(x);
    schw+=a[x];
    schc+=b[x];
    for (int i=0;i<g[x].size();i++)
    {
        if (!b1[g[x][i]])
        {
            b1[g[x][i]]=true;
            dfs(g[x][i]);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    cin>>n>>m>>W;
    g.resize(n+1); ans.resize(n+1);
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) cin>>b[i];

    for (int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i=1;i<=n;i++)
    {
        if (!b1[i])
        {
            k++;
            b1[i]=true;
            dfs(i);
            sum.push_back(make_pair(schw,schc));
            /*for (int i=0;i<ans[k].size();i++)
                cout<<ans[k][i]<<" ";
            cout<<endl;*/
            schw=schc=0;
        }
    }
    for (int i=1;i<=k;i++)
    {
        for (int j=1;j<=W;j++)
        {
            for (int j1=0;j1<ans[i].size();j1++)
                if (a[ans[i][j1]]<=j)
                dp[i][j]=max(max(dp[i-1][j],dp[i][j]),dp[i-1][j-a[ans[i][j1]]]+b[ans[i][j1]]);

            if (sum[i].first<=j)
                dp[i][j]=max(max(dp[i][j],dp[i-1][j]),dp[i][j-sum[i].first]+sum[i].second);
            else
                dp[i][j]=max(dp[i][j],dp[i-1][j]);

        }
    }

    /*for (int i=1;i<=k;i++)
    {
        for (int j=1;j<=W;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/

    cout<<dp[k][W];
    return 0;
  }


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

int n,m,w;
int a[100500];
int b[100500];
bool c[100500];
int res,res1,k1,k;
vector <vector <int> > g;
vector <pair<int,int> > p;

int dfs(int x)
{
    for (int i=0;i<g[x].size();i++)
        if (!c[g[x][i]])
        {
            c[g[x][i]]=true;
            cout<<res<<"x"<<res1<<" "<<k1<<endl;
            if (res1+a[g[x][i]]<=w && (res1<a[g[x][i]] && a[g[x][i]]<=w))
            {
                if (res+b[g[x][i]]>b[g[x][i]])
                {
                    res+=b[g[x][i]];
                    res1+=a[g[x][i]];
                    k1++;
                }
                else
                {
                    res=b[g[x][i]];
                    res1=a[g[x][i]];
                    k1=1;
                }
            }
            else if (res1+a[g[x][i]]>w && (res1<a[g[x][i]] && a[g[x][i]]>w))
            {
                res=b[g[x][i]];
                res1=a[g[x][i]];
                k1=1;
            }
            else if (res1+a[g[x][i]]>w && ((res1<a[g[x][i]] && a[g[x][i]]>w)))
            {
                res+=b[g[x][i]];
                res1+=a[g[x][i]];
                k1++;
            }
            cout<<res<<"x"<<res1<<" "<<k1<<"out"<<endl;
           k++;
            dfs(g[x][i]);
        }
    return k;
}

int main()
{
    cin>>n>>m>>w;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++) cin>>b[i];

    g.resize(n+1);
    for (int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i=1;i<=n;i++)
    {
        if (c[i]) continue;
        g[i].push_back(i);
        dfs(i);
        if (k1==1 || k1==k)
            p.push_back(make_pair(res,res1));

        res=res1=k1=k=0;
    }
    for (int i=0;i<p.size();i++)
        cout<<p[i].first<<" "<<p[i].second<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <iterator>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n,m,W,k,schw,schc;
int a[2000],b[2000];
bool b1[2000];
int dp[2000][2000];
vector<vector<int> > g,ans(1);
vector<pair<int,int> > sum(1);

void dfs(int x)
{
    ans[k].push_back(x);
    schw+=a[x];
    schc+=b[x];
    for (int i=0;i<g[x].size();i++)
    {
        if (!b1[g[x][i]])
        {
            b1[g[x][i]]=true;
            dfs(g[x][i]);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    cin>>n>>m>>W;
    g.resize(n+1); ans.resize(n+1);
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) cin>>b[i];

    for (int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i=1;i<=n;i++)
    {
        if (!b1[i])
        {
            k++;
            b1[i]=true;
            dfs(i);
            sum.push_back(make_pair(schw,schc));
            /*for (int i=0;i<ans[k].size();i++)
                cout<<ans[k][i]<<" ";
            cout<<endl;*/
            schw=schc=0;
        }
    }
    for (int i=1;i<=k;i++)
    {
        for (int j=1;j<=W;j++)
        {
            for (int j1=0;j1<ans[i].size();j1++)
                if (a[ans[i][j1]]<=j)
                dp[i][j]=max(max(dp[i-1][j],dp[i][j]),dp[i-1][j-a[ans[i][j1]]]+b[ans[i][j1]]);

            if (sum[i].first<=j)
                dp[i][j]=max(max(dp[i][j],dp[i-1][j]),dp[i][j-sum[i].first]+sum[i].second);
            else
                dp[i][j]=max(dp[i][j],dp[i-1][j]);

        }
    }

    for (int i=1;i<=k;i++)
    {
        for (int j=1;j<=W;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }

    cout<<dp[k][W];
    return 0;
  }