Project Management
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 730 accepted submission (s): 258
Problem description we have built a big project! This project has n nodes and is connected by many sides. This project is connected!
Two nodes may have multiple edges, but the two ends of an edge must be different nodes.
Each node has an energy value.
Now we need to compile a project management software, which has two operations:
1. Add a specific value to the energy value of a project.
2. Ask the sum of the energy values of projects adjacent to a project. (If multiple edges exist multiple times, for example, if a and B have two edges, the weight of B is calculated twice when a is asked ).
The first line of input is an integer T (1 <=t <= 3), indicating the number of test data.
For each test data, the first row has two integers, n (1 <= n <= 100000) and M (1 <= m <= N + 10 ), number of points and number of sides, respectively.
Then, in m rows, two numbers A and B in each row indicate an edge between A and B.
Then an integer Q.
Then, for row Q, the first number of rows cmd indicates the operation type. If the CMD value is 0, the following two U v values indicate that the energy value of the project U is increased by V (0 <= V <= 100 ).
If CMD is 1, the next number u table shows the sum of the energy values of neighboring U projects.
Number of all vertices from 1 to n.
Output indicates the answer for each query.
Sample Input
13 21 21 360 1 150 3 41 11 30 2 331 2
Sample output
41515
We mainly want to learn about STL, and containers are convenient.
# Include "stdio. H "# include" vector "# include" string. H "# define n 100100 using namespace STD; vector <int> G [N]; int C [N]; int main () {int T, A, B, n, m, Q, op, I; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); for (I = 0; I <= N; I ++) // clear the container G [I]. clear (); While (M --) {scanf ("% d", & A, & B); G [B]. push_back (a); // input data, which is a two-dimensional array G [A]. push_back (B);} scanf ("% d", & Q); memset (C, 0, sizeof (c); While (Q --) {scanf ("% d", & OP); If (OP = 0) {scanf ("% d", & A, & B ); c [a] + = B;} else {int S = 0; scanf ("% d", & A); for (I = 0; I <G [A]. size (); I ++) // convenient data access {S + = C [G [a] [I];} printf ("% d \ n", S) ;}} return 0 ;}