题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
1 3 2 1 2 1 3 6 0 1 15 0 3 4 1 1 1 3 0 2 33 1 2
4 15 15
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <queue> #include <vector> using namespace std; const int N=100017; int c[N]; vector<int>p[N]; int main() { int T; int n, m, a, b; int Q; int i, j; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(i = 1; i <= n; i++) p[i].clear(); for(i = 1; i <= m; i++) { scanf("%d%d",&a,&b); p[a].push_back(b);//因为要求相邻的,分别添加 p[b].push_back(a); } scanf("%d",&Q); int op, u, v; memset(c,0,sizeof(c)); for(i = 1; i <= Q; i++) { scanf("%d",&op); if(op == 0) { scanf("%d%d",&u,&v); c[u]+=v; } else if(op == 1) { scanf("%d",&u); int ans = 0; int size = p[u].size(); for(i = 0; i < size; i++) { ans+=c[p[u][i]]; } printf("%d\n",ans); } } } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/38048799