Cod sursa(job #2233085)

Utilizator patcasrarespatcas rares danut patcasrares Data 22 august 2018 10:57:17
Problema Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<fstream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<unordered_map>
#include<iostream>
#include<cstring>
#define DN 200005
#define x first
#define y second
#define pb push_back
using namespace std;
ifstream fin("andrei.in");
ofstream fout("andrei.out");
int n,m,f,g,type,viz[DN],top,s[DN],r[DN];
vector<int>v[DN];
void muchie(int f,int g)
{
    v[-f+n].pb(g+n);
    v[-g+n].pb(f+n);
}
void dfs(int nod)
{
    viz[nod]=1;
    for(auto i:v[nod])
        if(!viz[i])
            dfs(i);
    top++;
    s[top]=nod;
}
int main()
{
    fin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        fin>>f>>g>>type;
        if(type==0)
            muchie(f,g);
        if(type==1)
            muchie(-f,-g);
        if(type==2)
        {
            muchie(f,-g);
            muchie(-f,g);
        }
    }
    for(int i=0;i<=2*n;i++)
        if(!viz[i])
            dfs(i);
    for(int i=top;i>0;i--)
    {
        f=s[i]-n;
        g=-f;
        f+=n;
        g+=n;
        if(!r[f]&&!r[g])
            r[g]=1;
    }
    for(int i=1;i<=n;i++)
        fout<<r[i+n]<<' ';
}