Cod sursa(job #2942412)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 19 noiembrie 2022 17:36:38
Problema Andrei Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.55 kb
///intotdeauna dai search la cazurile imposibile
///si de acolo scoti implicatii

#include <fstream>
#include <vector>
#include <algorithm>
#include <bitset>
#pragma optimize GCC ("Ofast")

using namespace std;

ifstream cin ("andrei.in");
ofstream cout ("andrei.out");

const int N = 2e5;
int ctc[N + 1];

bitset <N + 1> viz;

vector <int> g[N + 1], gb[N + 1], v;

int n, m, cer, x, y, k;

void dfsplus (int node)
{
    viz[node] = 1;
    for (auto it : g[node])
        if (!viz[it])
            dfsplus(it);
    v.push_back(node);
}

void dfsminus (int node)
{
    ctc[node] = k;
    for (auto it : gb[node])
        if (!ctc[it])
            dfsminus(it);
}

void addmuchii (int x, int y)
{
    g[x].push_back(y);
    gb[y].push_back(x);
}

int main()
{
    for (cin >> n >> m; m && cin >> x >> y >> cer; --m)
    {
        if (cer == 0)
        {
            addmuchii (x, y + n);
            addmuchii (y, x + n);
        }
        else if (cer == 1)
        {
            addmuchii (x + n, y);
            addmuchii (y + n, x);
        }
        else
        {
            addmuchii (x, y);
            addmuchii (y, x);
            addmuchii (x + n, y + n);
            addmuchii (y + n, x + n);
        }
    }

    for (int i = 1; i <= (n << 1); ++i)
        if (!viz[i])
            dfsplus(i);
    reverse (v.begin(), v.end());
    for (auto it : v)
        if (!ctc[it])
            ++k, dfsminus (it);
    for (int i = 1; i <= n; ++i)
        cout << (ctc[i] < ctc[i + n]) << ' ';
    return 0;
}