Cod sursa(job #3345677)

Utilizator And_etcAndrei P And_etc Data 10 martie 2026 16:45:03
Problema Party Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.07 kb
#include <bits/stdc++.h>

using namespace std;

vector<int> v[505];
vector<int> vv[505];
int ct[505];
bool f[505];
vector<int> st;
int in;
vector<int> r;

void ctc(int k) {
    f[k] = 1;
    for(auto a : v[k]) {
        if(f[a] == 0) {
            ctc(a);
        }
    }
    st.push_back(k);
}

void bl(int k) {
    f[k] = 0;
    ct[k] = in;
    for(auto a : vv[k]) {
        if(f[a] == 1) {
            bl(a);
        }
    }
}

int main() {
    ifstream cin("party.in");
    ofstream cout("party.out");

    int n, m, x, y, t, a, b;
    cin >> n >> m;

    for(int i = 1; i <= m; ++i) {
        cin >> x >> y >> t;

        if(t == 0) {
            a = x + n;
            b = y;
            v[a].push_back(b);
            vv[b].push_back(a);
            a = y + n;
            b = x;
            v[a].push_back(b);
            vv[b].push_back(a);
        } else if(t == 1) {
            a = x + n;
            b = y + n;
            v[a].push_back(b);
            vv[b].push_back(a);
            a = y;
            b = x;
            v[a].push_back(b);
            vv[b].push_back(a);
        } else if(t == 2) {
            a = y + n;
            b = x + n;
            v[a].push_back(b);
            vv[b].push_back(a);
            a = x;
            b = y;
            v[a].push_back(b);
            vv[b].push_back(a);
        } else {
            a = x;
            b = y + n;
            v[a].push_back(b);
            vv[b].push_back(a);
            a = y;
            b = x + n;
            v[a].push_back(b);
            vv[b].push_back(a);
        }
    }

    for(int i = 1; i <= 2 * n; ++i) {
        if(f[i] == 0) {
            ctc(i);
        }
    }

    for(int h = st.size() - 1; h >= 0; --h) {
        if(f[st[h]] == 1) {
            ++in;
            bl(st[h]);
        }
    }

    for(int i = 1; i <= n; ++i) {
        if(ct[i] > ct[i + n]) {
            r.push_back(i);
        }
    }

    cout << r.size() << "\n";
    for(auto a : r) {
        cout << a << "\n";
    }

    return 0;
}