Pagini recente » Cod sursa (job #2286670) | Cod sursa (job #2311518) | Cod sursa (job #2884964) | Cod sursa (job #461166) | Cod sursa (job #3133679)
#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 = 32e4+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];
void init(){
for(int i = 1 ; i <= n ; i++){
h[i] = t[i] = val[i] = 0;
}
}
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;
if(h[x] == h[y]){
t[y] = x;
val[y] = c;
h[x]++;
}else{
if(h[x]<h[y])swap(x,y);
t[y] = x;
val[y] = c;
}
}
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++);
if(i == (int)xs.size()){
return val[ys[i]];
}else if( i == (int)ys.size()){
return val[xs[i]];
}else return min(val[xs[i]],val[ys[i]]);
}
}uf;
signed main(){
cin >> n >> m >> p;
int x , y;
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;
}
qx = (qx*a+qy*b)%n + 1;
qy = (qy*c+val*d)%n + 1;
}
return 0;
}