Pagini recente » Cod sursa (job #3221471) | Cod sursa (job #2391628) | Cod sursa (job #285513) | Cod sursa (job #2283080) | Cod sursa (job #2634109)
#include <bits/stdc++.h>
using namespace std;
ifstream ci("balanta.in");
ofstream cou("balanta.out");
int n,m;
int bal[1026];
int t1[1026][1026];
int t2[1026][1026];
int rezz[1026];
int maigrele[1026];
int maiusoare[1026];
void citire(){
ci>>n>>m;
int i;
for(i=1;i<=m;i++){
ci>>bal[i];
for(int j=1;j<=bal[i];j++){
ci>>t1[i][j];
}
for(int j=1;j<=bal[i];j++){
ci>>t2[i][j];
}
ci>>rezz[i];
}
for(i=1;i<=n;i++){
maigrele[i]=1;
maiusoare[i]=1;
}
}
void rez(){
int i,x;
int cng=0,cnu=0;
for(i=1;i<=m;i++){
if(rezz[i]==0){
for(int j=1;j<=bal[i];j++){
x=t1[i][j];
maigrele[x]=0;
maiusoare[x]=0;
//cout<<x<<" ";
}
for(int j=1;j<=bal[i];j++){
x=t2[i][j];
maigrele[x]=0;
maiusoare[x]=0;
//cout<<x<<" ";
}
}else
if(rezz[i]==1){
for(int j=1;j<=bal[i];j++){
x=t1[i][j];
//maigrele[x]=0;
maiusoare[x]=0;
}
for(int j=1;j<=bal[i];j++){
x=t2[i][j];
maigrele[x]=0;
//maiusoare[x]=0;
}
}else
if(rezz[i]==2){
for(int j=1;j<=bal[i];j++){
x=t1[i][j];
maigrele[x]=0;
//maiusoare[x]=0;
}
for(int j=1;j<=bal[i];j++){
x=t2[i][j];
//maigrele[x]=0;
maiusoare[x]=0;
}
}
}
for(i=1;i<=n;i++){
//cout<<i<<" "<<maigrele[i]<<" "<<maiusoare[i]<<"\n";
if(maigrele[i]==1){
cng++;
}
if(maiusoare[i]==1){
cnu++;
}
}
if(cng==1&&cnu>1){
for(i=1;i<=n;i++){
if(maigrele[i]==1){
cou<<i;
return;
}
}
}else
if(cnu==1&&cng>1){
for(i=1;i<=n;i++){
if(maiusoare[i]==1){
cou<<i;
return;
}
}
}else{
cou<<"0";
}
}
int main()
{
citire();
rez();
return 0;
}