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
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<bits/stdc++.h>

using namespace std;

int n, k, a, b;

vector<int> v[1000005];



vector<tuple<bool, int, int>> dodaj_promyki(){
  vector<tuple<bool, int,int>> result;
  queue<int> q;
  int odl[1000005];
  for(int i = 1 ; i <= n ; i++){
    odl[i] = -1;
  }
  odl[1] = 0;
  q.push(1);
  while(!q.empty()){
    int aktualny = q.front();
    q.pop();
    for(int sasiad : v[aktualny]){
      if(odl[sasiad] == -1){
        odl[sasiad] = odl[aktualny] + 1;
        q.push(sasiad);
        if(odl[sasiad] > 1){
          result.push_back({true, 1, sasiad});
          v[1].push_back(sasiad);
          v[sasiad].push_back(1);
        }
      }
    }
  }
  return result;
}

vector<tuple<bool, int, int>> usun_graf(){
  vector<tuple<bool, int,int>> result;
  for(int i = 2 ; i <= n ; i++){
    for(int j = 0 ; j < v[i].size() ; j++){
      int sasiad = v[i][j];
      if(sasiad > i){
        result.push_back({false, i, sasiad});
      }
    }
  }
  return result;

}

int main(){
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<tuple<bool, int,int>> p1;
  vector<tuple<bool, int,int>> u2;
  for(int wczytanie = 0 ; wczytanie < 2 ; wczytanie++){
    cin >> k;
    for(int i = 1 ; i <= n ; i++){
      v[i].clear();
    }
    for(int i = 0 ; i < k ; i++){
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    vector<tuple<bool, int,int>> promyki = dodaj_promyki();
    vector<tuple<bool, int,int>> usuniete = usun_graf();

    if(wczytanie == 0){
      // for(int i = 0 ; i < promyki.size() ; i++){
      //   cout << "+" << " " << get<1>(promyki[i]) << " " << get<2>(promyki[i]) << endl;
      // }
      // for(int i = 0 ; i < usuniete.size() ; i++){
      //   cout << "-" << " " << get<1>(usuniete[i]) << " " << get<2>(usuniete[i]) << endl;
      // }
      p1 = promyki;
      u2 = usuniete;
    }
    else{
      int rozmiar = promyki.size() + usuniete.size() + p1.size() + u2.size();
      cout << rozmiar << endl;
      for(int i = 0 ; i < p1.size() ; i++){
        cout << "+" << " " << get<1>(p1[i]) << " " << get<2>(p1[i]) << endl;
      }
      for(int i = 0 ; i < u2.size() ; i++){
        cout << "-" << " " << get<1>(u2[i]) << " " << get<2>(u2[i]) << endl;
      }
      for(int i = 0 ; i < usuniete.size() ; i++){
        cout << "+" << " " << get<1>(usuniete[i]) << " " << get<2>(usuniete[i]) << endl;
      }
      for(int i = 0 ; i < promyki.size() ; i++){
        cout << "-" << " " << get<1>(promyki[i]) << " " << get<2>(promyki[i]) << endl;
      }
    }
  }
}