Pagini recente » Cod sursa (job #2534229) | Cod sursa (job #827534) | Cod sursa (job #2307324) | Cod sursa (job #2534547) | Cod sursa (job #1074196)
#include <iostream>
#include <fstream>
using namespace std;
int max(int a[], int b)
{
int m = 0;
for(int i=0; i< b; i++)
{
if(a[i] > m) m = a[i];
}
return m;
}
int check(int a)
{
if(a< 0)
{
return 0-a;
}
if(a> 2)
{
return a-2;
}
return 0;
}
int main()
{
ifstream fin("balanta.in");
ofstream fout("balanta.out");
int n, m, temp1, temp2, p = 0;
fin>>n>>m;
int arr[n], check_arr[n];
for(int i=0; i< n; i++)
{
arr[i] = 1;
}
int temp[n];
for(int i =0; i< m; i++)
{
fin>>temp1;
for(int j=0; j< 2*temp1; j++)
{
fin>>temp[j];
}
fin>>temp2;
if(temp2 != 0)
{
if(temp2 == 1)
{
for(int j=0; j< temp1; j++)
{
arr[temp[j] - 1]++;
}
for(int j=temp1; j< 2*temp1; j++)
{
arr[temp[j] - 1]--;
}
}
else if(temp2 == 2)
{
for(int j=temp1; j< 2*temp1; j++)
{
arr[temp[j] - 1]++;
}
for(int j=0; j< temp1; j++)
{
arr[temp[j] - 1]--;
}
}
}
}
for(int i=0; i< n; i++)
{
check_arr[i] = check(arr[i]);
}
temp2 = max(check_arr, n);
int count = 0;
for(int i=0; i< n; i++)
{
if(check_arr[i] == temp2) count++;
}
for(int i=0; i< n; i++)
{
if(arr[i] == max(arr, n)) p = i+1;
}
if(count > 1) p = 0;
/*for(int i =0; i< n; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;*/
/*for(int i=0; i< n; i++)
{
if(i == 0)
{
if(arr[i] == 1 && arr[i+1] == 0) p = i+1;
}
else if(i == n-1)
{
if(arr[i] == 1 && arr[i-1] == 0) p = i+1;
}
else if(arr[i] == 1 && arr[i-1] == 0 && arr[i+1] == 0) p = i+1;
}*/
fout<<p<<endl;
return 0;
}