Pagini recente » Cod sursa (job #2858592) | Cod sursa (job #1917699) | Cod sursa (job #2549280) | Cod sursa (job #578961) | Cod sursa (job #3133697)
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
using pii = pair<int,int>;
ifstream cin("atac.in");
ofstream cout("atac.out");
const int MAX = 64e4+1;
struct muchie{
int x , y , c;
};
bool crit( muchie r , muchie l){
return r.c > l.c;
}
vector <muchie> edges;
int qx , qy , a , b , c , d , n , m , p;
struct DSU{
int h[MAX] , t[MAX] , val[MAX] , ind;
vector <int> g[MAX];
void init(){
for(int i = 1 ; i <= n ; i++){
h[i] = t[i] = val[i] = 0;
}
ind = n+1;
}
int findc( int x ){
while(t[x]) x = t[x];
return x;
}
void unionp( int x , int y , int c){
x = findc(x);
y = findc(y);
if(x == y) return;
t[x] = t[y] = ind;
val[ind] = c;
ind++;
}
int value( int x , int y ){
vector <int> xs;
vector <int> ys;
while(x){
xs.push_back(x);
x=t[x];
}
while(y){
ys.push_back(y);
y=t[y];
}
reverse(xs.begin(),xs.end());
reverse(ys.begin(),ys.end());
int i;
for(i = 0 ; i < (int)xs.size() && i < (int)ys.size() && xs[i]==ys[i]; i++);
return val[xs[i-1]];
}
}uf;
signed main(){
cin >> n >> m >> p;
int x , y;
uf.init();
for(int i = 2 ; i <= n ; i++){
cin >> x >> y;
edges.push_back({x,i,y});
}
sort(edges.begin(),edges.end(),crit);
for(auto it : edges){
uf.unionp(it.x,it.y,it.c);
}
cin >> qx >> qy >> a >> b >> c >> d;
for(int i = 1 ; i <= m ; i++){
int val = uf.value(qx,qy);
if(m - (i-1) <= p){
cout << val << '\n';
}
qx = (qx*a+qy*b)%n + 1;
qy = (qy*c+val*d)%n + 1;
}
return 0;
}