题意 \(T\) 组数据,每组数据给定一棵 \(n\) 个点的树和 \(m\) 条路径,求选出 \(k\) 条给定路径使得至少有两条交于一点的方案数,对 \(10^9+7\) 取模. \(\texttt{Data Range:}1\leq T\leq 200,1\leq n\leq 3\times 10^5,2\leq m\leq 3\times 10^5,2\leq k\leq m\). 题解 这种题都不能一次 AC,而且还是犯的弱智错误,我太菜了. 考虑这样一个结论:如果两条路径交于一些点,…
A. Rikka with Minimum Spanning Trees 题意: 给出一个图,求最小生成树的个数和权值 思路: 因为数据随机,只有一个MST #include <bits/stdc++.h> using namespace std; #define ull unsigned long long ull k1, k2; ; int t, n, m; ull f() { ull k3 = k1, k4 = k2; k1 = k4; k3 ^= k3 << ; k2 =…
题目链接:2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest A. Rikka with Minimum Spanning Trees 题意: 给出一个随机算法生成边的信息,然后求最小生成树的个数以及其权值的乘积. 题解: 这个随机算法有点神奇...基本不会有重复的边出现,所以其实只用求MST就行了.当然,其实通过样例也可以猜出来,样例生成了1W条边,但最后的answer就为最小生成树权值,所以可以直接根据这个来猜一发,注意一下判断是否连通就行了.…
Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being forc…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 207    Accepted Submission(s): 63 Problem Description Problems that process input and generate a simple ``yes'' or ``no'' answer are called decis…
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] 这道题给我们一个二叉树,让我们返回所有根到叶节点的路径,跟之前那道Path Sum II 二叉树路径之和之二很类似,比那道稍微简单一…
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl…
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in t…
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] 思路:用两个stack<TreeNode*> in , s; in : 记录当前的路径 p  , 和vector<…
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径. f[i][j][k]从下往上到第i层第j个和为k的方案数 上下转移不一样,分开处理 没必要判断走出沙漏 打印方案倒着找下去行了,尽量往左走   沙茶的忘注释掉文件WA好多次   #include <iostream> #include <cstdio> #include <a…