Pagini recente » Cod sursa (job #178090) | Cod sursa (job #2034853) | Cod sursa (job #1736482) | Cod sursa (job #285438) | Cod sursa (job #2034264)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
vector <pair<int,int> > graf[100001] ;
bool viz[100001] ;
bool t[100001] ;
int n , m ;
void citire ()
{
int i , x , y , c ;
ifstream fin ("andrei.in") ;
fin >> n >> m ;
memset(viz,false,n+1) ;
memset(t,0,n+1) ;
for ( i = 1 ; i <= m ; i++ )
{
fin >> x >> y >> c ;
graf[x].push_back(make_pair(y,c)) ;
}
}
void arcu ( int x , int y )
{
//cout << " intru in arcu cu marcu " << x << " " << y << " " << graf[x][y].second ;
if ( graf[x][y].second == 0 || graf[x][y].second == 1 )
{
if ( t[x] == 0 )
t[graf[x][y].first] = 1 ;
else
t[graf[x][y].first] = 0 ;
}
else if ( graf[x][y].second == 2 )
t[graf[x][y].first] = t[x] ;
//cout << " am pus in el " << t[graf[x][y].first] << endl ;
}
void DFS ( int nod )
{
//cout << " intru in DFS " << nod << endl ;
int i ;
viz[nod] = true ;
for ( i = 0 ; i < graf[nod].size() ; i++ )
{
if ( viz[graf[nod][i].first] == false )
{
arcu(nod,i) ;
//cout << " aiciiicii " ;
DFS(graf[nod][i].first) ;
}
}
}
int main()
{
ofstream fout ("andrei.out") ;
citire() ;
for ( int i = 1 ; i <= n ; i++ )
{
if ( viz[i] == false )
{
t[i] = 0 ;
DFS(i) ;
}
}
for ( int i = 1 ; i <= n ; i++ )
fout << t[i] << " " ;
}