Advertisement
1kostik1

D1

Oct 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector< pair<bool,int> > check(1000009,make_pair(false,-10));
  6.  
  7. struct point {
  8.     vector<int> parent;
  9.     int value;
  10.     int number;
  11.     vector<int> children;
  12. };
  13.  
  14. vector<point> graph;
  15.  
  16. void creatPoint(int f) {
  17.     point p;
  18.     p.value=f;
  19.     p.number=graph.size();
  20.     check[f]=make_pair(true,p.number);
  21.     graph.push_back(p);
  22. }
  23.  
  24. void loc(int f,int s) {
  25.     if(check[f].first==false) creatPoint(f);
  26.     if(check[s].first==false) creatPoint(s);
  27.  
  28.     int lf=check[f].second;
  29.     int ls=check[s].second;
  30.  
  31.     graph[lf].children.push_back(graph[ls].value);
  32.     graph[ls].parent.push_back(graph[lf].value);
  33. }
  34.  
  35. bool find(int f,int s,int t) {
  36. int lf=check[f].second;
  37. int ls=check[s].second;
  38. int lt=check[t].second;
  39. point pf = graph[lf]; point ps = graph[ls]; point pt = graph[lt];
  40. bool bf=false; bool bs=false; bool bt=false;
  41.  
  42.  
  43.  
  44. if(pf.parent.size()==0) bf=true;
  45. if(ps.parent.size()==0) bs=true;
  46. if(pt.parent.size()==0) bt=true;
  47.  
  48.  
  49. if(bf==true) {
  50.  
  51. if(bs==true) {
  52.  
  53. if(bt==true) return true;
  54.  
  55. else if(bt==false) {
  56. int kp = pt.parent.size();
  57. if(kp>2) return false;
  58. if(kp==1) {
  59. if(pt.parent[0]==pf.value||pt.parent[0]==ps.value) return true;
  60. else return false;
  61. } else if(kp==2) {
  62. int a=pt.parent[0]; int b=pt.parent[1];
  63. if((a==pf.value&&b==ps.value)||(b==ps.value&&a==pf.value)) return true;
  64. else return false;
  65. }
  66. }
  67.  
  68. }
  69.  
  70.  
  71. else if(bs==false) {
  72.  
  73. if(bt==true) {
  74. int ks = ps.parent.size();
  75. if(ks>1) return false;
  76. if(ks==1) if(ps.parent[0]==pf.value) return true;  
  77. return false;
  78. }
  79.  
  80.  
  81. else if(bt==false) {
  82.  
  83.  
  84. int ks = ps.parent.size();
  85. if(ks>1) return false;
  86. if(ks==1) if(ps.parent[0]!=pf.value) return false;
  87.  
  88.  
  89. int kt = pt.parent.size();
  90. if(kt>2) return false;
  91. if(kt==1) {  
  92.  
  93. if(pt.parent[0]==pf.value) return true;
  94. else if(pt.parent[0]==ps.value) return true;
  95. else return false;
  96. } else if(kt==2) {
  97.  
  98. int a = pt.parent[0]; int b = pt.parent[1];
  99. if(a==pf.value&&b==ps.value) return true;
  100. else if(a==ps.value&&b==pf.value) return true;
  101. else return false;
  102.  
  103. }
  104.  
  105. }
  106.  
  107. }
  108.  
  109. }else return false;
  110.  
  111. return true;  
  112.  
  113. }
  114.  
  115.  
  116. int main() {
  117.     int n,m;
  118.     cin>>n>>m;
  119.     for(int i=0;i<m;i++) {
  120.         int f,s;
  121.         cin>>f>>s;
  122.         loc(f,s);
  123.     }
  124.  
  125.     for(int i=0;i<n;i++) {
  126.         int f,s,t;
  127.         cin>>f>>s>>t;
  128.         bool b = find(f,s,t);
  129.         if(b) cout<<"honest\n";
  130.         else cout<<"liar\n";
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement