Codeforces 838 B - Diverging Directions】的更多相关文章

B - Diverging Directions 思路: 用dfs序+线段树维护子树中距离(从1到u,再从u到1)的最小值 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define L…
B. Diverging Directions 题意 给出一个n个点2n-2条边的有向图.n-1条指向远离根方向的边形成一棵树,还有n-1条从非根节点指向根节点的边. q次操作,1修改第x条边权值为y,2询问,求u到v的最短距离. 题解 在前n-1条边上dfs得到dfs序. 用线段树维护从根到区间里的点的最短距离,和从根到区间里的点再回去的最短距离. 修改第一条边的边权时,就修改了根到这条边指向的点为根的子树里每个点的距离.x为根的子树的点dfs序为L[x]~R[x]. 修改第二种边的边权时,只…
题目链接:http://codeforces.com/problemset/problem/838/B You are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2n - 2. The graph's edges can be split into two parts.…
描述 给你一个图,一共有 N 个点,2*N-2 条有向边. 边目录按两部分给出 1. 开始的 n-1 条边描述了一颗以 1 号点为根的生成树,即每个点都可以由 1 号点到达. 2. 接下来的 N-1 条边,一定是从 i 到 1(2<=i<=N)的有向边,保证每个点都能到达 有 q 次询问: 1 x w :表示将第 x 条边的边权修改为 w 2 u v :询问 u 到 v 的最短距离 [输入格式] 第一行是 2 个整数 N,Q,表示一共 N 个点 Q 次询问 接下来是 N-1 行,每行 3 个整…
0 写在前面 怎么说呢,其实从入坑线段树一来,经历过两个阶段,第一个阶段是初学阶段,那个时候看网上的一些教学博文和模板入门了线段树, 然后挑选了一个线段树模板作为自己的模板,经过了一点自己的修改,然后就已知用着,其实对线段树理解不深,属于就会套个模板的状态,期间有人问我线段树的问题,我其实也半知不解的, 后来,刷了几道DFS序+线段树的题目,那个时候多多少少有所长进,再次回过头来重新看线段树的代码,理解有所加深,算是勉强理清了线段树这个东西, 再到现在,前不久刚把splay搞完,对平衡二叉搜索树…
A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or o…
B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be…
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. He lives in a circular park. There are n trees around the park. The distance between the i-th tree and (i + 1)-st trees is di, the distance between t…
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Memory is performing a walk on the two-dimensional plane, starti…
题目链接: http://codeforces.com/problemset/problem/77/C C. Beavermuncher-0xFF time limit per test:3 secondsmemory limit per test:256 megabytes 问题描述 "Eat a beaver, save a tree!" - That will be the motto of ecologists' urgent meeting in Beaverley Hill…