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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ssize(a) ((int)(a.size()))

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<vector<int>>pol(n + 1), pol2(n + 1);
    vector<unordered_map<int, bool>>czyp(n + 1), czyp2(n + 1);
    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        pol[a].push_back(b);
        pol[b].push_back(a);
        czyp[a][b] = 1;
        czyp[b][a] = 1;
    }
    //dodaje krawedzie od 1 do n
    int start = pol[1][0];
    vector<pair<char, pair<int, int>>>odp;
    for(int i = -1; i <= 1; i += 2)
        for(int j = start + i; j > 1 && j <= n; j += i)
        {
            if(czyp[1][j] == 0)
            {
                odp.push_back({'+', {1, j}});
            }
        }

    int m2;
    cin >> m2;
    for(int i = 0; i < m2; ++i)
    {
        int a, b;
        cin >> a >> b;
        pol2[a].push_back(b);
        pol2[b].push_back(a);
        czyp2[a][b] = 1;
        czyp2[b][a] = 1;
    }

    for(int i = 2; i <= n; ++i)
    {
        for(int j:pol[i])
            if(j > i)
            {
                if(!czyp2[i][j])
                    odp.push_back({'-', {i, j}});
            }
        for(int j:pol2[i])
            if(j > i)
            {
                if(!czyp[i][j])
                    odp.push_back({'+', {i, j}});
            }
    }

    start = pol2[1][0];
    for(int j = 2; j < start; ++j)
    {
        if(czyp2[1][j] == 0)
        {
            odp.push_back({'-', {1, j}});
        }
    }
    for(int j = n; j > start; --j)
    {
        if(czyp2[1][j] == 0)
        {
            odp.push_back({'-', {1, j}});
        }
    }

    cout << odp.size() << endl;
    for(auto i: odp)
        cout << i.first << ' ' << i.second.first << ' ' << i.second.second << endl;
    return 0;
}