Cod sursa(job #2942436)

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

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

using namespace std;

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

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

bitset <N + 1> viz;

vector <uint32_t> 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()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        cin >> x >> y >> cer;
        if (cer == 0)
        {
            addmuchii (x, y + n);
            addmuchii (y, x + n);
        }
        if (cer == 1)
        {
            addmuchii (x + n, y);
            addmuchii (y + n, x);
        }
        if (cer == 2)
        {
            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;
}