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
#include <bits/stdc++.h>

using namespace std;

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

struct lolz{
  char c;
  int a;
  int b;
}typedef lolz;

  map<pair<int,int>,bool> mp;
  map<pair<int,int>,bool> mp2;
  vector<pair<int,int>> E;
  vector<lolz> S;
  int n;cin>>n;
  int m1;cin>>m1;
  vector <int> v;
  vector < vector<int> >V1(n+1,v);
  for(int i=0;i<m1;i++){
    int a,b;cin>>a>>b;
    pair<int,int> p;p.first=a;p.second=b;
    E.push_back(p);
    mp[p]=true;
    V1[a].push_back(b);
    V1[b].push_back(a);
  }

  sort(V1[1].begin(),V1[1].end());
  auto it=V1[1].begin();
  for(int i=2;i<=n;i++){
    if(it==V1[1].end() or *it>i){
      S.push_back((lolz){'+',1,i});//"+ 1 "+to_string(i)+"\n");
      pair<int,int> p;p.first=1;p.second=i;
      mp[p]=true;
      E.push_back(p);
    }
    else it++;
  }
  for(int i=2;i<=n;i++)v.push_back(i);
  V1[1]=v;v.clear();
  
  int m2;cin>>m2;
  vector < vector<int> >V2(n+1,v);
  for(int i=0;i<m2;i++){
    int a,b;cin>>a>>b;
    V2[a].push_back(b);
    V2[b].push_back(a);
    pair<int,int> p1;p1.first=a;p1.second=b;
    pair<int,int> p2;p2.first=b;p2.second=a;
    mp2[p1]=true;mp2[p2]=true;
    if(!mp.count(p1) and !mp.count(p2)){
      S.push_back((lolz){'+',a,b});//"+ "+to_string(a)+" "+to_string(b)+"\n");
    }
  }
  for(int i=0;i<E.size();i++){
    if(!mp2.count(E[i])) S.push_back((lolz){'-',E[i].first,E[i].second});//"- "+to_string(E[i].first)+" "+to_string(E[i].second)+"\n");
  }
  cout<<S.size()<<"\n";
  for(int i=0;i<S.size();i++)cout<<S[i].c<<" "<<S[i].a<<" "<<S[i].b<<"\n";
}