#include <bits/stdc++.h>
using namespace std;
int n,m,w,f[10010];
int v[10010],p[10010],nv[10010],np[10010],vv[10010],pp[10010];
int dp[10010];
int cnt;
void bag(){
for(int i = 1;i <= n;i++)
for(int j = w;j >= np[i];j--)
dp[j]=max(dp[j],dp[j-np[i]]+nv[i]);
cout << dp[w] << " ";
}
int find(int f[],int x){
return f[x]==x?f[x]:f[x]=find(f[x]);
}
void hb(int x,int y){
int t1 = find(f,x);
int t2=find(f,y);
if(t1!=t2){
f[t2]=t1;
}
}
void init(){
for(int i = 1;i <= n;i++){
f[i]=i;
}
}
signed main(){
cin >> n >> m >> w;
for(int i = 1;i <= n;i++){
cin >> p[i] >> v[i];
}
init();
for(int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
hb(x,y);
}
for(int i = 1;i <= n;i++){
pp[find(f,i)]=pp[f[i]]+p[i];
vv[find(f,i)]=vv[f[i]]+v[i];
}
for(int i = 1;i <= n;i++){
if(pp[i]>0){
cnt++;
np[cnt]=pp[i];
nv[cnt]=vv[i];
}
}
bag();
return 0;
}
WA #1#2#3#4,但是#1的样例下载下来跑确实是对的,和样例输出一样,那为什么会WA呢?可能是哪里有错?