#include <bits/stdc++.h>
using namespace std;
int n,m,w;
struct node
{
int v,w;
};
vector<node> g[10005];
int fa[10005],c[10005],d[10005],summ[10005],sumv[10005];
int w0[10005],v[10005],dp[3][10005];
bool f[10005];
int find(int x)
{
if(x == fa[x])return x;
return fa[x] = find(fa[x]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> w;
for(int i = 1;i <= n;i++)
{
fa[i] = i;
cin >> c[i] >> d[i];
}
for(int i = 1;i <= m;i++)
{
int a,b;
cin >> a >> b;
int one = find(a);
int two = find(b);
if(one == two)continue;
fa[one] = two;
}
for(int i = 1;i <= n;i++)
{
summ[find(i)] += c[i];
sumv[find(i)] += d[i];
}
int cur = 0;
for(int i = 1;i <= n;i++)
{
if(!f[find(i)])
{
cur++;
w0[cur] = summ[find(i)];
v[cur] = sumv[find(i)];
}
}
for(int i = 1;i <= cur;i++)
{
for(int j = 0;j <= w;j++)
{
if(j < w0[i])
{
dp[i%2][j] = dp[(i-1)%2][j];
}
else
{
dp[i%2][j] = max(dp[(i-1)%2][j],dp[(i-1)%2][j-w0[i]]+v[i]);
}
}
}
cout << dp[cur%2][w];
return 0;
}
并查集统计云朵所连成的联通块,然后01背包求答案,WA第4个点。