Pagini recente » Cod sursa (job #863977) | Cod sursa (job #1385274) | Cod sursa (job #2290253) | Cod sursa (job #3031633) | Cod sursa (job #1940919)
#include<fstream>
#include<stack>
#include<vector>
#define DIM 200005
using namespace std;
ifstream fin("andrei.in");
ofstream fout("andrei.out");
int n, m, x, y, c, val[DIM], niv[DIM], low[DIM], cod, f[DIM], nr;
vector<int> v[DIM];
stack<int> st;
void dfs( int nod ){
cod++;
niv[nod] = low[nod] = cod;
f[nod] = 1;
st.push( nod );
for( int i = 0; i < v[nod].size(); i++ ){
int vecin = v[nod][i];
if( niv[vecin] == 0 ){
dfs( vecin );
low[nod] = min( low[nod], low[vecin] );
}else{
if( f[vecin] == 1 ){
low[nod] = min( low[nod], low[vecin] );
}
}
}
if( niv[nod] == low[nod] ){
nr++;
while( st.top() != nod ){
int x = st.top();
f[x] = 0;
if( val[x] == 0 ){
val[x] = 1;
if( x <= n ){
val[x + n] = -1;
}else{
val[x - n] = -1;
}
}
st.pop();
}
int x = st.top();
f[x] = 0;
if( val[x] == 0 ){
val[x] = 1;
if( x <= n ){
val[x + n] = -1;
}else{
val[x - n] = -1;
}
}
st.pop();
}
return;
}
int main(){
fin >> n >> m;
for( int i = 1; i <= n; i++ ){
fin >> x >> y >> c;
if( c == 0 ){
v[x + n].push_back(y);
v[y + n].push_back(x);
continue;
}
if( c == 1 ){
v[x].push_back(y + n);
v[y].push_back(x + n);
continue;
}
v[x].push_back(y);
v[y].push_back(x);
v[x + n].push_back(y + n);
v[y + n].push_back(x + n);
}
cod = 0;
for( int i = 1; i <= n * 2; i++ ){
if( niv[i] == 0 ){
dfs( i );
}
}
for( int i = 1; i <= n; i++ ){
fout << ( val[i] > 0 ) << " ";
}
return 0;
}