【题目链接】点击打开链接
【解题思路】qwb巨BLOG: 点击打开链接
【AC代码】
//
//Created by BLUEBUFF 2016/1/9
//Copyright (c) 2016 BLUEBUFF.All Rights Reserved
//
#pragma comment(linker,"/STACK:102400000,102400000")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include <sstream> //isstringstream
#include <iostream>
#include <algorithm>
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, LL> pp;
#define REP1(i, a, b) for(int i = a; i < b; i++)
#define REP2(i, a, b) for(int i = a; i <= b; i++)
#define REP3(i, a, b) for(int i = a; i >= b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define MP(x, y) make_pair(x,y)
template <class T1, class T2>inline void getmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void getmin(T1 &a, T2 b) { if (b<a)a = b; }
const int maxn = 200010;
const int maxm = 100010;
const int maxs = 10;
const int maxp = 1e3 + 10;
const int INF = 1e9;
const int UNF = -1e9;
const int mod = 1e9 + 7;
//int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;
//head
struct edge{
int u, v;
}E[maxn];
vector <int> G[maxn];
int du[maxn], A[maxn], sum[maxn];
int n, m, q, block;
void update(int x, int d){
A[x] += d;
for(int i = 0; i < G[x].size(); i++){
int v = G[x][i];
sum[v] += d;
}
}
int query(int x){
if(du[x] < block){
sum[x] = 0;
for(int i = 0; i < G[x].size(); i++){
int v = G[x][i];
sum[x] += A[v];
}
return sum[x];
}
else{
return sum[x];
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
CLR(A, 0); CLR(sum, 0); CLR(du, 0);
REP2(i, 1, n) G[i].clear();
REP2(i, 1, m){
scanf("%d%d", &E[i].u, &E[i].v);
du[E[i].u]++; du[E[i].v]++;
}
block = sqrt(m + 0.5);
REP2(i, 1, m){
int u = E[i].u, v = E[i].v;
if(du[u] < block) G[u].push_back(v);
else if(du[v] >= block) G[u].push_back(v);
if(du[v] < block) G[v].push_back(u);
else if(du[u] >= block) G[v].push_back(u);
}
scanf("%d", &q);
while(q--)
{
int cmd, a, b;
scanf("%d", &cmd);
if(cmd == 0){
scanf("%d%d", &a, &b);
update(a, b);
}
else{
scanf("%d", &a);
printf("%d\n", query(a));
}
}
}
return 0;
}