Pagini recente » Cod sursa (job #727283) | Cod sursa (job #2459167) | Cod sursa (job #3279778)
#include <fstream>
#include <stack>
#include <vector>
#define dim (int)(2e5+1)
using namespace std;
ifstream cin("andrei.in");
ofstream cout("andrei.out");
int n,m,x,y,k,tip,nr,minlv[dim],niv[dim],sol[dim];
vector<int>v[dim];
stack<int>s;
bool viz[dim],in[dim];
void dfs(int nod,int t){
s.push(nod);
in[nod]=1;
viz[nod]=1;
niv[nod]=minlv[nod]=niv[t]+1;
for(auto i:v[nod])
if(!viz[i]){
dfs(i,nod);
if(in[i])
minlv[nod]=min(minlv[nod],minlv[i]);
}else if(in[i])
minlv[nod]=min(minlv[nod],niv[i]);
if(minlv[nod]==niv[nod]){
while(!s.empty()&&s.top()!=nod){
sol[s.top()]=nr;
in[s.top()]=1;
s.pop();
}
s.pop();
in[nod]=0;
sol[nod]=nr;
nr++;
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>x>>y>>tip;
if(tip==0){
v[x].push_back(n+y);
v[y].push_back(n+x);
}else if(tip==1){
v[n+y].push_back(x);
v[n+x].push_back(y);
}else{
v[x].push_back(y);
v[y].push_back(x);
v[n+y].push_back(n+x);
v[n+x].push_back(n+y);
}
}
for(int i=1;i<=2*n;i++)
if(!viz[i])
dfs(i,0);
for(int i=1;i<=n;i++)
if(sol[i]<sol[i+n])
cout<<1<<" ";
else
cout<<0<<" ";
return 0;
}