Cod sursa(job #1996300)

Utilizator DjokValeriu Motroi Djok Data 30 iunie 2017 21:51:26
Problema Party Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Semestrul 2 Marime 0.82 kb
#include <bits/stdc++.h>
#define rand() dis(gen)
using namespace std;

const int N = 1005;
mt19937 gen(time(0));
uniform_int_distribution<int> dis(0, 1e6);

int i, n, m, x[N], y[N], z[N], val[N], nx[N], ny[N], rs;

int main() {
  ifstream cin("party.in");
  ofstream cout("party.out");
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  for(i = 1; i <= m; ++i) {
    cin >> x[i] >> y[i] >> z[i];

    if(z[i] == 1) ny[i] = 1;
    if(z[i] == 2) nx[i] = 1;
    if(z[i] == 3) nx[i] = ny[i] = 1;
  }

  for(i = 1; i <= m; ++i)
    if(!(val[x[i]] ^ nx[i]) && !(val[y[i]] ^ ny[i])) {
      if(rand() & 1) val[x[i]] ^= 1;
      else val[y[i]] ^= 1;
      i = 0;
    }

  for(i = 1; i <= n; ++i) if(val[i]) ++rs;

  cout << rs << '\n';
  for(i = 1; i <= n; ++i) if(val[i]) cout << i << '\n';

  return 0;
}