开始版刷SGU啦,SGU的题都是几十个点一道。。。MD一道题卡死你
#include <bits/stdc++.h>
using namespace std;
#define begin Begin
#define next Next
#define count Count
#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; ++i)
#define DR(i, a, b) for (int i = (a), _begin_ = (b); i >= _begin_; --i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
template<typename T> inline bool chkmin(T &a, const T &b){ return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b){ return a < b ? a = b, 1 : 0; }
typedef long long LL;
const int dmax = 310, maxn = 10, oo = 0x3f3f3f3f;
int N, M;
int a[dmax][dmax], d[maxn], cnt, S;
struct edge
{
int x, y;
edge(const int &_x = 0, const int &_y = 0) : x(_x), y(_y) {}
}c[dmax], s[dmax];
void dfs(int x)
{
REP(i, 0, 6)
if (a[x][i])
{
--a[x][i], --a[i][x];
dfs(i);
s[++cnt] = edge(x, i);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
scanf("%d", &N);
REP(i, 1, N)
{
int x, y;
scanf("%d%d", &x, &y);
++a[x][y], ++a[y][x];
++d[x], ++d[y];
c[i] = edge(x, y);
}
REP(i, 0, 6)
if (d[i] & 1)
{
++cnt;
S = i;
} else if (d[i] && !S) S = i;
if (cnt > 2)
{
puts("No solution");
return 0;
}
cnt = 0;
dfs(S);
if (cnt < N)
{
puts("No solution");
return 0;
}
DR(i, cnt, 1)
REP(j, 1, N)
if (s[i].x == c[j].x && s[i].y == c[j].y)
{
printf("%d +\n", j);
c[j].x = -1;
break;
} else if (s[i].x == c[j].y && s[i].y == c[j].x)
{
printf("%d -\n", j);
c[j].x = -1;
break;
}
return 0;
}