Pagini recente » Cod sursa (job #1854524) | Cod sursa (job #1534857) | Cod sursa (job #1171672) | Cod sursa (job #1628768) | Cod sursa (job #2630215)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("andrei.in");
ofstream g("andrei.out");
const int N=100005;
int n,m,who[N];
vector < pair < int, int > > v[N];
void find_group ( int a, int b, int c )
{
if(who[a]==1)
{
if(!c)
who[b]=2;
else
who[b]=1;
}
else
if(who[a]==2)
{
if(c==1)
who[b]=1;
else
who[b]=2;
}
}
void go_group ( int a, int b, int c )
{
if(who[a] && !who[b])
{
find_group(a,b,c);
return;
}
if(who[b] && !who[a])
{
find_group(b,a,c);
return;
}
if(!who[a] && !who[b])
{
who[a]=1;
go_group(a,b,c);
}
}
void Read ()
{
int i,a,b,c;
f>>n>>m;
for(i=1;i<=m;i++)
{
f>>a>>b>>c;
v[a].push_back(make_pair(b,c));
go_group(a,b,c);
}
}
void out ()
{
int i;
for(i=1;i<=n;i++)
g<<who[i]-1<<" ";
}
int main()
{
Read();
out();
return 0;
}