-
Notifications
You must be signed in to change notification settings - Fork 2
/
FILLMTR1.cpp
115 lines (97 loc) · 3.51 KB
/
FILLMTR1.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int t;
cin>>t;
while(t--)
Your Rank: 24 Your Score: 3
{
long int n,q,m=0;
bool stop=1;
cin>>n>>q;
Your Rank: 24 Your Score: 3
map< pair<long int,long int>, int> matrix;
//vector<long int> arr[n];
//vector<long int> arr1;
//vector<bool> mark(1000005,0);
for(long int i=0;i<q;i++)
{
long int a,b,mina,maxb;
int val;
cin>>a>>b>>val;
a=a-1;b=b-1;
val=val+1;
mina=min(a,b);
maxb=max(a,b);
if(mina==maxb&&val==2)
{
stop=0;
}
else if(matrix.count(make_pair(mina,maxb)))
{
if(matrix[make_pair(mina,maxb)]!=val)
{
stop=0;
}
}
Your Rank: 24 Your Score: 3
else if(mina!=maxb)
{
matrix[make_pair(mina,maxb)]=val;
//cout<<arr1[m-1]<<endl;
}
//cout<<matrix[mina][maxb]<<" ";
}
if(stop==0)
{
cout<<"no"<<endl;
}
else
{
for (map<pair<long int,long int>,int>::iterator it = matrix.begin();it != matrix.end();++it)
{
map<pair<long int,long int>,int>::iterator it1 = it;
for (++it1;it1 != matrix.end()&&it->first.first==it1->first.first&&it->first.first<;++it1 )
{
long int x1,y1,x2,y2;
x1=it->first.first;
y1=it->first.second;
x2=it1->first.first;
y2=it1->first.second;
// cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
long int a,b,mini,maxj;
a=it->first.second;
b=it1->first.second;
mini=min(a,b);
maxj=max(a,b);
int c1=it->second,c2=it1->second;
if(matrix.count(make_pair(mini,maxj))>0)
{
int c=c1+c2+matrix[make_pair(mini,maxj)];
if(c==4||c==6)
{
stop=0;
it1=matrix.end();
it=matrix.end();
}
}
else
{
int c=c1+c2;
if(c<3)
matrix[make_pair(mini,maxj)]=1;
else
matrix[make_pair(mini,maxj)]=5-c;
Your Rank: 24 Your Score: 3
}
}
}
if(stop)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
matrix.clear();
}
}