比赛 |
4043级NOIP2022欢乐赛2nd |
评测结果 |
AAAAAAAAAA |
题目名称 |
液体运输 |
最终得分 |
100 |
用户昵称 |
yrtiop |
运行时间 |
1.979 s |
代码语言 |
C++ |
内存使用 |
40.33 MiB |
提交时间 |
2022-10-31 19:17:28 |
显示代码纯文本
#include <bits/stdc++.h>
#define pb emplace_back
const int maxn = 4e5 + 5;
struct node {
int u,v,t;
node() {
u = v = t = 0;
}
node(int u,int v,int t):u(u),v(v),t(t){}
}E[maxn];
int n,m,pre[maxn],val[maxn],cnt,f[maxn][20],sz[maxn],d[maxn],a[maxn];
std::vector<int> G[maxn];
int find(int x) {
return x == pre[x] ? x : pre[x] = find(pre[x]);
}
void dfs(int u) {
for(auto& v : G[u]) {
d[v] = d[u] + 1;
f[v][0] = u;
for(int k = 1;(1 << k) <= d[v];++ k)
f[v][k] = f[f[v][k - 1]][k - 1];
dfs(v);
}
return ;
}
int main() {
freopen("Xen.in","r",stdin);
freopen("Xen.out","w",stdout);
scanf("%d %d",&n,&m);
for(int i = 1;i <= m;++ i)
scanf("%d %d %d",&E[i].u,&E[i].v,&E[i].t);
for(int i = 1;i <= n;++ i)
scanf("%d",&a[i]);
for(int i = 1;i <= n * 2;++ i)pre[i] = i;
for(int i = 1;i <= n;++ i)sz[i] = 1;
cnt = n;
std::sort(E + 1 , E + 1 + m , [&](const node& p,const node& q) {
return p.t > q.t;
});
for(int i = 1;i <= m;++ i) {
int u = find(E[i].u),v = find(E[i].v);
if(u == v)continue ;
pre[u] = pre[v] = ++ cnt;
G[cnt].pb(u);
G[cnt].pb(v);
val[cnt] = E[i].t;
sz[cnt] = sz[u] + sz[v];
a[cnt] = std::min(a[u] , a[v]);
}
dfs(cnt);
int Q,q,ans = 0;
scanf("%d %d",&Q,&q);
while(Q --) {
int p,s,mod;
scanf("%d %d %d",&p,&s,&mod);
p = (p + q * ans) % n + 1;
s = (s + q * ans) % mod;
for(int k = 19;~ k;-- k)
if(f[p][k]&&val[f[p][k]] >= s)p = f[p][k];
// printf("TEST:%d\n",p);
printf("%d %d\n",sz[p],ans = a[p]);
}
return 0;
}