hdu 4858 项目管理(vector模拟)
- # include <stdio.h>
- # include <algorithm>
- # include <string.h>
- # include <vector>
- # define N 100005
- using namespace std;
- vector<int>g[N];
- int node[N];
- int slove(int x)
- {
- int sum=0,i;
- for(i=0;i<g[x].size();i++)
- {
- sum+=node[g[x][i]];
- }
- return sum;
- }
- int main()
- {
- int t,a,b,c,n,m,q,i;
- while(~scanf("%d",&t))
- {
- while(t--)
- {
- scanf("%d%d",&n,&m);
- for(i=1;i<=n;i++)
- {
- g[i].clear();
- node[i]=0;
- }
- while(m--)
- {
- scanf("%d%d",&a,&b);
- g[a].push_back(b);
- g[b].push_back(a);
- }
- scanf("%d",&q);
- while(q--)
- {
- scanf("%d",&a);
- if(a==0)
- {
- scanf("%d%d",&b,&c);
- node[b]+=c;
- }
- else
- {
- scanf("%d",&c);
- printf("%d\n",slove(c));
- }
- }
- }
- }
- return 0;
- }
hdu 4858 项目管理(vector模拟)的更多相关文章
- HDU 4858 项目管理(邻接表 暴力模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...
- hdu 4858 项目管理 图的分块
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的!两个节点间可能 ...
- HDU 4858 项目管理 分块
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4858 题解: 下面说一个插入查询时间复杂度为sqrt(m)的算法: 对每个点定义两个值:val,su ...
- hdu 4858 项目管理(STL集装箱)
项目管理 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU - 4858 项目管理
N个点,M条无向边.现在有Q组操作,一种是给 i号点增加能量,一种是询问 i号点相邻点的能量和(点间有多条边就算两次). 据说暴力能过,但还是用这题学习了一下 点分块 . 度数不超过 sqrt(M) ...
- hdu 4841 圆桌问题(用vector模拟约瑟夫环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4841 圆桌问题 Time Limit: 3000/1000 MS (Java/Others) M ...
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- UVa 12100 Printer Queue(queue或者vector模拟队列)
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- 利用C++ STL的vector模拟邻接表的代码
关于vector的介绍请看 https://www.cnblogs.com/zsq1993/p/5929806.html https://zh.cppreference.com/w/cpp/conta ...
随机推荐
- HDU 3947 River Problem
River Problem Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ...
- Codeforces Round #407 (Div. 2) B+C!
B. Masha and geometric depression 被这个题坑了一下午,感觉很水,一直WA在第14组,我那个气啊,结束后发现第14组有点小争议,于是找出题人解释,然后出题人甩给了我一段 ...
- Android圆弧背景
代码改变世界 Android圆弧背景 <?xml version="1.0" encoding="utf-8"?><shape xmlns:a ...
- BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积
[题目分析] 卷积一卷. 然后分块去一段一段的求. O(n)即可. [代码] #include <cstdio> #include <cstring> #include < ...
- [luoguP2324] [SCOI2005]骑士精神(A*?)
传送门 蒟蒻并不懂A*是什么,但是题解里有个Astar 可以看出,当前棋盘和最终的棋盘如果有k个不同的,那么至少需要k-1步来移动 所以如果 当前步数 + k - 1 > limit 就直接退出 ...
- RSA工作原理
摘自:http://www.ruanyifeng.com/blog/2013/07/rsa_algorithm_part_two.html 一.基础数论 1.互质关系 如果两个正整数,除了1以外,没有 ...
- leetcode 349 map
只需要用map来标记1,今儿通过map的值来得到重叠的部分 class Solution { public: vector<int> intersection(vector<int& ...
- [无趣]bit reverse
真不想承认啊,因为年轻而犯下的错误! inline void _BR(int* a,int r){ for(int i=0,j=1;i<r;++i,j<<=1){ for(int k ...
- javaweb学习总结(八)——HttpServletResponse对象(二)(转)
(每天都会更新至少一篇以上,有兴趣的可以关注)转载自孤傲苍狼 一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedI ...
- 【Tyvj1982】武器分配(费用流)
题意:有N个人要从A个物品中各取一个,B个物品中各取一个,选取第i个A类物品和第j个B类物品的费用是(a[i]-b[j])^2 求最小总花费 n<=a,b<=80 a[i],b[i]< ...