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
//泥の分際で私だけの大切を奪おうだなん
#include<bits/stdc++.h>
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
vector<int> e[30003];
char op[200003];
int x[200003],y[200003],tot;
int u[50003],v[50003];
bool vis[30003],flg[30003];
void dfs(int u,int fa=0)
{
	vis[u]=1;
	for(int v:e[u]) if(!vis[v])
	{
		if(!flg[v]) op[++tot]='+',x[tot]=1,y[tot]=v;
		dfs(v);
	}
}
signed main()
{
	int n=read(),m=read();
	for(int i=1; i<=m; ++i)
		u[i]=read(),v[i]=read(),
		e[u[i]].push_back(v[i]),
		e[v[i]].push_back(u[i]);
	for(int i=1; i<=m; ++i)
		if(u[i]==1||v[i]==1)
			flg[u[i]+v[i]-1]=1;
	flg[1]=1,dfs(1);
	for(int i=1; i<=m; ++i)
		if(u[i]!=1&&v[i]!=1)
			op[++tot]='-',x[tot]=u[i],y[tot]=v[i];
	m=read(),memset(vis,0,sizeof(vis)),
	memset(flg,0,sizeof(flg));
	int cur=tot;
	for(int i=1; i<=n; ++i) e[i].clear();
	for(int i=1; i<=m; ++i)
		u[i]=read(),v[i]=read(),
		e[u[i]].push_back(v[i]),
		e[v[i]].push_back(u[i]);
	for(int i=1; i<=m; ++i)
		if(u[i]==1||v[i]==1)
			flg[u[i]+v[i]-1]=1;
	flg[1]=1,dfs(1);
	for(int i=1; i<=m; ++i)
		if(u[i]!=1&&v[i]!=1)
			op[++tot]='-',x[tot]=u[i],y[tot]=v[i];
	reverse(op+cur+1,op+tot+1),
	reverse(x+cur+1,x+tot+1),
	reverse(y+cur+1,y+tot+1);
	for(int i=cur+1; i<=tot; ++i)
		if(op[i]=='+') op[i]='-'; else op[i]='+';
	printf("%d\n",tot);
	for(int i=1; i<=tot; ++i)
		printf("%c %d %d\n",op[i],x[i],y[i]);
	return 0;
}