#include #include #include using namespace std; #define pb push_back #define se second #define fi first #define FOR(i,n) for(int j=i;j > graph [],vector& c,int z) { if(visited[i]==1) return ; visited[i]=1; for(int j = 0 ; j < graph[i].size();j++) { if(visited[graph[i][j].first]==0) { if(c[graph[i][j].first]==0 && c[i]==0) { if(z>0&&z<=y) { if(c[z]==1) { int b; for(b = 0 ; b 0&&z<=y) { if(c[z]==0){ int b; for(b = 0 ; b > n; vector c(n+1); for(int c_i = 1; c_i <= n; c_i++){ cin >> c[c_i]; if(c[c_i]==0) reds++; else blacks++; } y=n; ans = 0; pair a,b; vector< pair > graph[n+1]; for(int a0 = 0; a0 < n-1; a0++){ int u; int v; int w; cin >> u >> v >> w; a.first = u ; a.second = w ; b.first = v; b.second = w; graph[u].pb(b); graph[v].pb(a); } /*for(int i = 1; i<=n ;i++) { cout << i << "---->"; for(int j = 0 ; j < graph[i].size() ;j++) { cout << graph[i][j].first << " " <> p >> d>>m>>s; int ans = 0; while(s>=0) { if(p-ans*d >= m){ if(s-(p-ans*d)>=0) { s -= (p-ans*d); ans++; } else break; } else { if(s-m>=0) { ans++; s-=m; } else break; } } cout << ans; }