Pagini recente » Cod sursa (job #3152938) | Cod sursa (job #394883) | Cod sursa (job #931430) | Cod sursa (job #903437) | Cod sursa (job #2593479)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("andrei.in");
ofstream fout("andrei.out");
// Începe să-mi placă mai mult CodeForces decât InfoArena.
// Acolo nu iei MLE pentru simplul fapt că folosești STL sau OOP...
const int NMAX = 2e5 + 1;
int n, m;
vector<int> adG[NMAX], adT[NMAX];
int top, topo[NMAX];
vector<bool> vis, ans;
inline int non(int x) {
return (x > n ? x - n : x + n);
}
void addEdge(int x, int y) {
adG[x].push_back(y);
adT[y].push_back(x);
}
void dfsG(int node) {
vis[node] = true;
for (int nghb : adG[node])
if (!vis[nghb])
dfsG(nghb);
topo[top++] = node;
}
void dfsT(int node) {
vis[node] = false;
ans[non(node)] = true;
for (int nghb : adT[node])
if (vis[nghb])
dfsT(nghb);
}
void addProp(int x, int y) {
if (x < 0) x = n - x;
if (y < 0) y = n - y;
addEdge(non(x), y);
addEdge(non(y), x);
}
void solve() {
vis.resize(2 * n + 1);
for (int i = 1; i <= 2 * n; i++)
if (!vis[i])
dfsG(i);
reverse(topo, topo + 2 * n);
ans.resize(2 * n + 1);
for (int node : topo)
if (vis[node] && vis[non(node)])
dfsT(node);
}
int main() {
fin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y, t; fin >> x >> y >> t;
if (t == 0)
addProp(+x, +y);
else if (t == 1)
addProp(-x, -y);
else {
addProp(-x, +y);
addProp(+x, -y);
}
}
solve();
for (int i = 1; i <= n; i++)
fout << ans[i] << ' ';
fout << '\n';
fout.close();
return 0;
}