MSBOP 2015 Round2B register

Ended

Participants:6187

Verdict:AC | RE
Submitted:2015-04-26 15:38:23

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <cstdlib>
int n, m, q, a[105][105];
int color[105], x, y, z;
void work()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &color[i]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            a[i][j] = 0;
    for (int i = 1; i <= m; i++)
        scanf("%d %d %d", &x, &y, &z), a[x][y] = a[y][x] = z;
    for (int i = 1; i <= q; i++)
    {
        int type;
        scanf("%d", &type);
        if (type == 1)
            scanf("%d", &x), color[x] ^= 1;
        else if (type == 2)
            scanf("%d %d %d", &x, &y, &z), a[x][y] = a[y][x] = z;
        else
        {
            int s = 0;
            for (int j = 1; j < n; j++)
                for (int k = j + 1; k <= n; k++)
                    s += (color[j] != color[k]) * a[j][k];
            printf("%d\n", s);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX