Pagini recente » Cod sursa (job #3120469) | Cod sursa (job #1713019) | Cod sursa (job #27548) | Cod sursa (job #1940217) | Cod sursa (job #2236238)
#include <bits/stdc++.h>
#define NMAX 105
#define INF 0x3f3f3f3f
#define MOD 1000003
#define pb push_back
#define x first
#define y second
using namespace std;
ifstream fin("party.in");
ofstream fout("party.out");
int n, nr;
stack<int> st;
vector<int> G[NMAX], GT[NMAX];
bool viz[NMAX], stare[NMAX];
inline int negat(int x) {
if(x<=n) return x+n;
return x-n;
}
void DFSp(int x) {
viz[x] = 1;
for(auto it:G[x])
if(!viz[it]) DFSp(it);
st.push(x);
}
void DFSm(int x) {
viz[x] = 0;
if(x > n) {
++nr;
stare[negat(x)] = 1;
}
for(auto it:GT[x])
if(viz[it]) DFSm(it);
}
int main() {
int m,i,x,y,t;
fin>>n>>m;
for(i=1;i<=m;++i) {
fin>>x>>y>>t;
if(t == 1) y = negat(y);
else if(t == 2) x = negat(x);
else if(t == 3) x = negat(x), y = negat(y);
G[negat(x)].pb(y);
G[negat(y)].pb(x);
GT[x].pb(negat(y));
GT[y].pb(negat(x));
}
for(i=1;i<=2*n;++i)
if(!viz[i])
DFSp(i);
while(!st.empty()) {
if(viz[st.top()] && viz[negat(st.top())])
DFSm(st.top());
st.pop();
}
fout << nr << '\n';
for(i=1;i<=2*n;++i)
if(stare[i]) fout << i << '\n';
return 0;
}