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

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;

const int N=30007;

int n;

bool is[N];
bool odw[N];

vector<int>G[N];
vector<pair<int,pair<int,int>>>ans;

void dfs(int v)
{
	odw[v]=1;
	for(auto u:G[v]) if(!odw[u]) dfs(u);
	if(!is[v]) ans.pb({1,{1,v}});
}


vector<pair<int,pair<int,int>>> calc(vector<pair<int,int>>E)
{
	ans.clear();
	for(int i=1;i<=n;i++)
	{
		is[i]=0;
		odw[i]=0;
		G[i].clear();
	}
	for(auto [a,b]:E)
	{
		if(a==1) is[b]=1;
		else if(b==1) is[a]=1;
		else 
		{
			ans.pb({0,{a,b}});
			G[a].pb(b);
			G[b].pb(a);
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(is[i]&&!odw[i]) dfs(i);
	}
	return ans;
}


signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    int m1;
    cin>>m1;
    vector<pair<int,int>>E1(m1);
    for(int i=0;i<m1;i++) 
    {
		cin>>E1[i].st>>E1[i].nd;
	}
    vector<pair<int,pair<int,int>>>res=calc(E1);
    reverse(all(res));
    int m2;
    cin>>m2;
    vector<pair<int,int>>E2(m2);
    for(int i=0;i<m2;i++)
    {
		cin>>E2[i].st>>E2[i].nd;
}
    vector<pair<int,pair<int,int>>>res1=calc(E2);
    for(auto [a,p]:res1) res.pb({a^1,p});
    cout<<sz(res)<<endl;
    for(auto [a,p]:res)
    {
		if(a==1) cout<<"+ ";
		else cout<<"- ";
		cout<<p.st<<" "<<p.nd<<endl;
	}

    return 0;
}