1. # include <stdio.h>
  2. # include <algorithm>
  3. # include <string.h>
  4. # include <vector>
  5. # define N 100005
  6. using namespace std;
  7. vector<int>g[N];
  8. int node[N];
  9. int slove(int x)
  10. {
  11. int sum=0,i;
  12. for(i=0;i<g[x].size();i++)
  13. {
  14. sum+=node[g[x][i]];
  15. }
  16. return sum;
  17. }
  18. int main()
  19. {
  20. int t,a,b,c,n,m,q,i;
  21. while(~scanf("%d",&t))
  22. {
  23. while(t--)
  24. {
  25. scanf("%d%d",&n,&m);
  26. for(i=1;i<=n;i++)
  27. {
  28. g[i].clear();
  29. node[i]=0;
  30. }
  31. while(m--)
  32. {
  33. scanf("%d%d",&a,&b);
  34. g[a].push_back(b);
  35. g[b].push_back(a);
  36. }
  37. scanf("%d",&q);
  38. while(q--)
  39. {
  40. scanf("%d",&a);
  41. if(a==0)
  42. {
  43. scanf("%d%d",&b,&c);
  44. node[b]+=c;
  45. }
  46. else
  47. {
  48. scanf("%d",&c);
  49. printf("%d\n",slove(c));
  50. }
  51. }
  52. }
  53. }
  54. return 0;
  55. }

hdu 4858 项目管理(vector模拟)的更多相关文章

  1. HDU 4858 项目管理(邻接表 暴力模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...

  2. hdu 4858 项目管理 图的分块

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的!两个节点间可能 ...

  3. HDU 4858 项目管理 分块

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4858 题解: 下面说一个插入查询时间复杂度为sqrt(m)的算法: 对每个点定义两个值:val,su ...

  4. hdu 4858 项目管理(STL集装箱)

    项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. HDU - 4858 项目管理

    N个点,M条无向边.现在有Q组操作,一种是给 i号点增加能量,一种是询问 i号点相邻点的能量和(点间有多条边就算两次). 据说暴力能过,但还是用这题学习了一下 点分块 . 度数不超过 sqrt(M) ...

  6. hdu 4841 圆桌问题(用vector模拟约瑟夫环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4841 圆桌问题 Time Limit: 3000/1000 MS (Java/Others)    M ...

  7. uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟

    挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...

  8. UVa 12100 Printer Queue(queue或者vector模拟队列)

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  9. 利用C++ STL的vector模拟邻接表的代码

    关于vector的介绍请看 https://www.cnblogs.com/zsq1993/p/5929806.html https://zh.cppreference.com/w/cpp/conta ...

随机推荐

  1. HDU 3947 River Problem

    River Problem Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ...

  2. Codeforces Round #407 (Div. 2) B+C!

    B. Masha and geometric depression 被这个题坑了一下午,感觉很水,一直WA在第14组,我那个气啊,结束后发现第14组有点小争议,于是找出题人解释,然后出题人甩给了我一段 ...

  3. Android圆弧背景

    代码改变世界 Android圆弧背景 <?xml version="1.0" encoding="utf-8"?><shape xmlns:a ...

  4. BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积

    [题目分析] 卷积一卷. 然后分块去一段一段的求. O(n)即可. [代码] #include <cstdio> #include <cstring> #include < ...

  5. [luoguP2324] [SCOI2005]骑士精神(A*?)

    传送门 蒟蒻并不懂A*是什么,但是题解里有个Astar 可以看出,当前棋盘和最终的棋盘如果有k个不同的,那么至少需要k-1步来移动 所以如果 当前步数 + k - 1 > limit 就直接退出 ...

  6. RSA工作原理

    摘自:http://www.ruanyifeng.com/blog/2013/07/rsa_algorithm_part_two.html 一.基础数论 1.互质关系 如果两个正整数,除了1以外,没有 ...

  7. leetcode 349 map

    只需要用map来标记1,今儿通过map的值来得到重叠的部分 class Solution { public: vector<int> intersection(vector<int& ...

  8. [无趣]bit reverse

    真不想承认啊,因为年轻而犯下的错误! inline void _BR(int* a,int r){ for(int i=0,j=1;i<r;++i,j<<=1){ for(int k ...

  9. javaweb学习总结(八)——HttpServletResponse对象(二)(转)

    (每天都会更新至少一篇以上,有兴趣的可以关注)转载自孤傲苍狼 一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedI ...

  10. 【Tyvj1982】武器分配(费用流)

    题意:有N个人要从A个物品中各取一个,B个物品中各取一个,选取第i个A类物品和第j个B类物品的费用是(a[i]-b[j])^2 求最小总花费 n<=a,b<=80 a[i],b[i]< ...