Codeforces 702E Analysis of Pathes in Functional Graph(倍增)
来源:互联网 发布:淘宝店铺类目 编辑:程序博客网 时间:2024/06/05 22:29
代码:
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define MAX 100005#define MAXN 1000005#define maxnode 205#define sigma_size 26#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define pii pair<int,int>#define bits(a) __builtin_popcount(a)#define mk make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-4;const LL mod = 1e9+7;const ull mx = 133333331;/*****************************************************/inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; }/*****************************************************/int pre[MAX][40];int w[MAX][40];LL s[MAX][40];LL ans1;int ans2;void solve(int u,LL k){ if(k==0){ return ; } int t=0; while((1LL<<t)<=k) t++; t--; ans1+=s[u][t]; ans2=min(ans2,w[u][t]); solve(pre[u][t],k-(1LL<<t));}int main(){ //freopen("in.txt","r",stdin); int n; LL k; while(cin>>n>>k){ for(int i=0;i<n;i++) scanf("%d",&pre[i][0]); for(int i=0;i<n;i++) scanf("%d",&w[i][0]),s[i][0]=w[i][0]; for(int i=1;(1LL<<i)<=k;i++){ for(int j=0;j<n;j++){ pre[j][i]=pre[pre[j][i-1]][i-1]; w[j][i]=min(w[j][i-1],w[pre[j][i-1]][i-1]); s[j][i]=s[j][i-1]+s[pre[j][i-1]][i-1]; } } for(int i=0;i<n;i++){ ans1=0; ans2=INF; solve(i,k); printf("%I64d %d\n",ans1,ans2); } } return 0;}
0 0
- CodeForces 702E Analysis of Pathes in Functional Graph(倍增)
- Codeforces 702E Analysis of Pathes in Functional Graph(倍增)
- Educational Codeforces Round 15 E. Analysis of Pathes in Functional Graph (倍增RMQ)
- Educational Codeforces Round 15 E Analysis of Pathes in Functional Graph(倍增)
- Codeforces 702E - Analysis of Pathes in Functional Graph 二进制
- 【CF 702E】Analysis of Pathes in Functional Graph(倍增)
- Educational Codeforces Round 15 E. Analysis of Pathes in Functional Graph (倍增法)
- [CF 702E]Analysis of Pathes in Functional Graph
- Codeforces702E Analysis of Pathes in Functional Graph(倍增)
- Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
- CF702E - Analysis of Pathes in Functional Graph
- Educational Codeforces Round 15 Analysis of Pathes in Functional Graph rmq 变形
- Educational Codeforces Round 15 E. Analysis of Pathes in Functio(倍增)★ ★
- Educational Codeforces Round 15 E. Analysis of Pathes in Functio(每个点走k步会到达哪个点,经过的边中的最小值是多少,经过的边的权值和)
- Codeforces Round #326 (Div. 2) E. Duff in the Army(LCA+倍增法)
- Codeforces 405 E. Graph Cutting ( DFS )
- Codeforces 609E LCA倍增
- Codeforces 466 E. Information Graph
- XML解析之PULL解析
- 安卓谷歌电子市场学习笔记系列——ThreadPoolExecutor
- 解决 安卓SDK 下载packages失败问题
- 解决Cannot change version of project facet Dynamic web module to 3.0
- U3D 接入Android SDK 后,运行游戏闪退问题
- Codeforces 702E Analysis of Pathes in Functional Graph(倍增)
- XMLPULL解析
- Sereja and Swaps
- rails + capistrano + nginx + puma部署
- Android 自定义统计趋势图
- Androd7.0-新特性
- sequelize荟萃
- 关于makefile的规则
- 金蝶EAS 后台事务监控