#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define frs first
#define sec second
#define neparno(x) (x&1)
#define parno(x) (!neparno(x))
#define lowbit(x) (x&-x)
#define nzd __gcd
#define nzs(e1,e2) ((e1*e2)/nzd(e1,e2))
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define yesno(x) cout << ((x)?"Yes\n":"No\n")
#define condcout(x,y,z) cout << ((x)?y:z)
#define all(V) V.begin(),V.end()
#define fill(V,v) fill(all(V),v)
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin()
#define mod 1000000007
#define mxn 2000002
struct grana
{
ll v;
ll t;
ll o;
ll i;
};
ll q,n,m,s,R[mxn],T[mxn],U[mxn],VV[mxn];
bool V[mxn];
vector <grana> G[mxn];
ll DFS_MAX( ll i )
{
V[i] = true;
for ( auto x : G[i] )
{
ll next = x.v;
if ( V[next] )
{
continue;
}
R[x.i] = x.o;
DFS_MAX(next);
}
}
ll DFS_MIN( ll i )
{
V[i] = true;
for ( auto x : G[i] )
{
ll next = x.v;
if ( V[next] || x.t == 2 )
{
continue;
}
R[x.i] = x.o;
DFS_MIN(next);
}
}
ll Izbroj()
{
ll ret = 0;
for ( ll i = 1; i <= n; i++ )
{
ret += V[i];
}
return ret;
}
void Set()
{
for ( ll i = 1; i <= n; i++ )
{
V[i] = false;
}
}
int main()
{
ios;
cin >> n >> m >> s;
ll u,v,t;
for ( ll i = 1; i <= m; i++ )
{
cin >> t >> u >> v;
T[i] = t; U[i] = u; VV[i] = v;
if ( t == 1 )
{
G[u].push_back({v,1,-1,i});
}
else
{
G[u].push_back({v,2,0,i});
G[v].push_back({u,2,1,i});
}
}
DFS_MAX(s);
cout << Izbroj() << "\n";
for ( ll i = 1; i <= m; i++ )
{
if ( T[i] == 2 )
{
condcout(R[i],"-","+");
}
}
cout << "\n";
Set();
DFS_MIN(s);
cout << Izbroj() << "\n";
for ( ll i = 1; i <= m; i++ )
{
if ( T[i] == 2 )
{
if ( V[U[i]] && !V[VV[i]] )
{
R[i] = 1;
}
if ( !V[U[i]] && V[VV[i]] )
{
R[i] = 0;
}
condcout(R[i],"-","+");
}
}
cout << "\n";
return 0;
}
1302. Deepest Leaves Sum | 1209. Remove All Adjacent Duplicates in String II |
994. Rotting Oranges | 983. Minimum Cost For Tickets |
973. K Closest Points to Origin | 969. Pancake Sorting |
967. Numbers With Same Consecutive Differences | 957. Prison Cells After N Days |
946. Validate Stack Sequences | 921. Minimum Add to Make Parentheses Valid |
881. Boats to Save People | 497. Random Point in Non-overlapping Rectangles |
528. Random Pick with Weight | 470. Implement Rand10() Using Rand7() |
866. Prime Palindrome | 1516A - Tit for Tat |
622. Design Circular Queue | 814. Binary Tree Pruning |
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |