-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircuit.cpp
More file actions
87 lines (84 loc) · 1.57 KB
/
circuit.cpp
File metadata and controls
87 lines (84 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
using namespace std;
map<pair<long long int,long long int>,int >tar;
int main()
{
long long int t;
cin>>t;
while(t--)
{
long long int n,q,a,b,count,f=0,k=0;
cin>>n>>q;
map<pair<long long int,long long int>,int>::iterator it,it1,it2,it4;
while(q--)
{
cin>>a>>b;
pair<long long int,long long int>p;
p = make_pair(a,b-1);
tar[p]=1;
}
for(it=tar.begin();it!=tar.end();it++)
{
it1 = it;
it1 = ++it1;
it2 = it1;
it2 = ++it2;
if(it1!=tar.end() && it2!=tar.end() && (*it).first.first== (*it1).first.first && (*it1).first.first==(*it2).first.first)
{
count = (*it).first.first-1;
k=1;
break;
}
else if( it1!=tar.end() && (((*it1).first.first)-((*it).first.first))>1)
f=0;
else
{
if(it1!=tar.end() && (*it).first.first==(*it1).first.first)
{
if((*it).first.second==0 && (*it1).first.second==1 && f!=2)
{
f=1;
it = ++it;
}
else if((*it).first.second==0 && (*it1).first.second==2)
{
f=0;
it = ++it;
}
else if((*it).first.second==1 && (*it1).first.second==2 && f!=1)
{
f=2;
it = ++it;
}
}
else if(((*it1).first.first-(*it).first.first)==1)
{
if((*it).first.second==0)
{
f=0;
}
else if((*it).first.second==1)
{
f = f + 0;
}
else if((*it).first.second==2 && f!=2)
{
f=0;
}
}
else
{
k=1;
count = (*it).first.first;
break;
}
}
}
if(k==1)
cout<<count<<endl;
else
cout<<n<<endl;
tar.clear();
}
return 0;
}