Advertisement
Guest User

Untitled

a guest
May 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <set>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. bool f;
  9. int dim;
  10. int wr = 0;
  11. int ex = 0;
  12. bool used[10];
  13. bool bip1 = true;
  14. int parts[10];
  15. vector <int> graph[10];
  16. vector <int>component;
  17. vector <int>podgr[10];
  18. vector <int>podgr2[10];
  19. bool bip = true;
  20. set<int> mas;
  21. set<int>::iterator m;
  22. vector<int> mas2;
  23. vector<vector<int>> massiv;
  24. vector<int> helpMas;
  25. void checking(int top, int num)
  26. {
  27. parts[top] = num;
  28. for(int k = 0; k < podgr[top].size(); k++)
  29. if(parts[podgr[top][k] - 1] == 0)
  30. checking(podgr[top][k] - 1, 3-num);
  31. else if(parts[podgr[top][k] - 1] == num )
  32. {
  33. bip = false;
  34. }
  35.  
  36. }
  37.  
  38. void withDel()
  39. {
  40. for(int j = 0; j < 10; j++)
  41. for(int k = 0; k <= podgr[j].size(); k++)
  42. if(k!=podgr[j].size() || podgr[j].size()!=0)
  43. {
  44. if(parts[j]==0)
  45. {
  46. checking(j, 1);
  47. }
  48. if(bip == true)
  49. {
  50. ofstream fout;
  51. fout.open("output.out");
  52. fout << "Yes " << component.size() << endl;
  53. int p = 0;
  54. for (m = mas.begin(); m!= mas.end(); ++m)
  55. {
  56. if(p!=mas.size()-1)
  57. {
  58. fout << *m << " ";
  59. p++;
  60. }
  61. else
  62. fout << *m;
  63. }
  64. fout.close();
  65. wr = 1;
  66. bip = false;
  67. }
  68. if(bip == false)
  69. {
  70. j = 10;
  71. k = podgr[j].size()+1;
  72. //bip = true;
  73. for(int h = 0; h < 10; h++)
  74. cout << parts[h];
  75. cout << " not bip";
  76. }
  77. }
  78. }
  79.  
  80. void buildGraph()
  81. {
  82. for(int j = 0; j < component.size(); j++)
  83. {
  84. for(int u = 0; u < graph[component[j] - 1].size(); u++)
  85. podgr[component[j] - 1].push_back(graph[component[j] - 1][u]);
  86. }
  87. for(int x = 0; x < component.size(); x++)
  88. mas.insert(component[x]);
  89. for(int x = 0; x < component.size(); x++)
  90. mas2.push_back(component[x]);
  91. }
  92.  
  93. void trycheck(int top, int num,vector<int>vec)
  94. {
  95. /*bool u = true;
  96. for(int h = 0; h < vec.size(); h++)
  97. if(top==vec[h] - 1)
  98. u = false;
  99. if(u == true)*/
  100. if(parts[top] == 0)
  101. parts[top] = num;
  102. for(int v = 0; v < 10; v++)
  103. cout << parts[v] << " ";
  104. //cout << endl;
  105. //cout << u << endl;
  106. //cout << vec.size();
  107. for(int k = 0; k < podgr2[top].size(); k++){
  108. cout <<" K " << k <<" ";
  109. if(podgr2[top][k]!=-1 && parts[podgr2[top][k] - 1] == 0 )
  110. {
  111. cout << podgr2[top][k] << " ";
  112. trycheck(podgr2[top][k] - 1, 3-num,vec );
  113. }
  114. else if(podgr2[top][k]!=-1 && parts[podgr2[top][k] - 1] == num )
  115. {
  116. bip1 = false;
  117. //k = 10;
  118. f = true;
  119. for(int d = 0; d < 10; d++)
  120. parts[d]=0;
  121. return;
  122. }
  123. if(!bip1)
  124. return;
  125. }
  126. /*{
  127. bip = false;
  128. for(int d = 0; d < dim; d++)
  129. parts[d]=0;
  130. }*/
  131. }
  132. void secondCheck(vector<int> vec[], vector<int> str)
  133. {
  134. int dim1;
  135. /*for(int s = 0; s < 10; s++)
  136. podgr2[s].clear();*/
  137. for(int h = 0; h < 10; h++){
  138. for(int g = 0; g < podgr2[h].size(); g++)
  139. cout << podgr2[h][g] << " ";
  140. cout << endl;
  141. }
  142. cout <<"function";
  143. for(int j = 0; j < str.size(); j++)
  144. cout << str[j];
  145. for(int j = 0; j < str.size(); j++)
  146. for(int h = 0; h < 10; h++)
  147. for(int g = 0; g < vec[h].size(); g++)
  148. {
  149. if(podgr2[h].size()!=0){
  150. if(h == str[j] - 1)
  151. podgr2[h].clear();
  152. else
  153. {
  154. if(vec[h][g] == str[j])
  155. podgr2[h][g] = -1;
  156. }
  157. }
  158. }
  159. cout <<"function";
  160. for(int d = 0; d < 10; d++){
  161. for(int t = 0; t < podgr2[d].size(); t++)
  162. cout << podgr2[d][t] << " ";
  163. cout << endl;}
  164. /*for(int j = 0; j < 10; j++)
  165. for(int l = 0; l <= podgr2[j].size(); l++)
  166. if(l!=podgr2[j].size() || podgr2[j].size()!=0)*/
  167.  
  168. //if (parts[j] == 0)
  169. trycheck(0,1, str);
  170. for(int a = 0; a < 10; a++)
  171. parts[a] = 0;
  172. if(bip1 == true)
  173. {
  174. cout << "TRUE" << endl;
  175. mas.clear();
  176. cout<< str[0];
  177. for(int h = 0; h < component.size(); h++)
  178. cout <<component[h] <<" ";
  179. for(int n = 0; n < str.size(); n++)
  180. for(int h = 0; h < component.size(); h++)
  181. if(component[h]==str[n])
  182. component[h] = 0;
  183. for(int h = 0; h < component.size(); h++)
  184. if(component[h]!=0)
  185. mas.insert(component[h]);
  186. ofstream fout;
  187. fout.open("output.out");
  188. fout << "No" << endl;
  189. int p = 0;
  190. fout << str.size() << ":";
  191. for(int j = 0; j < str.size(); j++)
  192. {
  193. if(j!=str.size()-1)
  194. fout << str[j] << " ";
  195. else
  196. fout << str[j] << endl;
  197. }
  198. fout << component.size()-str.size() << ":";
  199. for (m = mas.begin(); m!= mas.end(); ++m)
  200. {
  201. if(p!=mas.size()-1)
  202. {
  203. fout << *m << " ";
  204. p++;
  205. }
  206. else
  207. fout << *m;
  208. }
  209. fout.close();
  210. ex = 1;
  211. }
  212. /*if(ex==1)
  213. {
  214. j = 10;
  215. l = podgr2[j].size()+1;
  216. }*/
  217. if(bip1 == false)
  218. {
  219. /*j = 10;
  220. l = podgr2[j].size()+1;*/
  221. bip1 = true;
  222. for(int h = 0; h < 10; h++)
  223. cout << parts[h];
  224. cout << " not bip";
  225. //break;
  226. }
  227. }
  228. void dfs(int top)
  229. {
  230. component.push_back(top + 1);
  231. used[top] = true;
  232. for(int l = 0; l < graph[top].size(); l++)
  233. if(!used[graph[top][l] - 1]&& graph[top][0]!= - 1 )
  234. dfs(graph[top][l] - 1);
  235. }
  236.  
  237. int main()
  238. {
  239. int aaa;
  240. ifstream fin;
  241. fin.open("input.in");
  242. fin >> dim;
  243. fin >> aaa;
  244. int first;
  245. int second;
  246. int k = 0;
  247. for(int i = 0; i < aaa; i++)
  248. {
  249. fin >> first;
  250. fin >> second;
  251. graph[first - 1].push_back(second);
  252. graph[second - 1].push_back(first);
  253. mas.insert(first);
  254. mas.insert(second);
  255. }
  256. for(int i = 0; i < mas.size(); i++)
  257. if(mas.count(i+1) == 0)
  258. graph[i].push_back(-1);
  259. for(int i = 0; i < dim; i++)
  260. {
  261. for(int j = 0; j < graph[i].size(); j++)
  262. cout << graph[i][j] << " ";
  263. cout << endl;
  264. }
  265. fin.close();
  266. int yes = 0;
  267. for(int i = 0; i < dim+1; i++)
  268. used[i] = false;
  269. for(int i = 0; i < dim; i++)
  270. if(!used[i])
  271. {
  272. //used[i] = true;
  273. component.clear();
  274. if(graph[i][0]!= -1)
  275. {
  276. if(i == 0)
  277. {
  278. dfs(i);
  279. cout << "component" << endl;
  280. for(int j = 0; j < component.size(); j++)
  281. cout << component[j] << " ";
  282. for(int j = 0; j < component.size(); j++)
  283. if(component[j] == 1)
  284. yes = 1;
  285. if(yes == 1)
  286. {
  287. for(int h = 0; h < dim; h++)
  288. {
  289. parts[h] = 0;
  290. }
  291. mas.clear();
  292. buildGraph();
  293. /*cout << "podgr" << endl;
  294. for(int u = 0; u < 10; u++)
  295. {
  296. for(int y = 0; y < podgr[u].size(); y++)
  297. cout << podgr[u][y] << " ";
  298. cout << endl;
  299. }*/
  300. cout << "parts";
  301. for(int j = 0; j < 10; j++)
  302. cout << parts[j] << " ";
  303. withDel();
  304. i = dim;
  305. bip = true;
  306.  
  307. }
  308. }
  309. else
  310. {
  311. dfs(i);
  312. cout << "component" << endl;
  313. for(int j = 0; j < component.size(); j++)
  314. cout << component[j] << endl;
  315. }
  316. }
  317. else
  318. {
  319. component.push_back(i+1);
  320. cout << "component" << endl;
  321. for(int j = 0; j < component.size(); j++)
  322. cout << component[j] << endl;
  323. }
  324. }
  325. int r = 0;
  326. for(int l = (1 << mas2.size()) - 1; l >=0; l--)
  327. {
  328. for(int u = 0; u < mas2.size(); u++)
  329. if(l & (1 << u))
  330. {
  331. if(typeid( mas2[u]) == typeid(int))
  332. cout << "yes";
  333. //cout << mas2[u] << " ";
  334. if(mas2[u]!=1)
  335. helpMas.push_back(mas2[u]);
  336. cout << mas2[u] << " ";
  337. }
  338. cout << endl;
  339. massiv.push_back(helpMas);
  340. helpMas.clear();
  341. r++;
  342. //cout << r<< endl;
  343. }
  344. if(wr == 0)
  345. {
  346. cout << "podgr" << endl;
  347. for(int u = 0; u < 10; u++)
  348. {
  349. for(int y = 0; y < podgr[u].size(); y++)
  350. cout << podgr[u][y] << " ";
  351. cout << endl;
  352. }
  353. for(int s = 0; s < 10; s++)
  354. for(int y = 0; y < podgr[s].size(); y++)
  355. podgr2[s].push_back(podgr[s][y]);
  356. cout <<"done";
  357. //вот тут я удалила код)
  358. for(int u = 0; u < massiv.size(); u++)
  359. {
  360. for(int r = 0; r < massiv[u].size(); r++)
  361. cout << massiv[u][r] << " ";
  362. cout << endl;
  363. }
  364. cout << "elem" << endl;
  365. for(int y = 0; y < massiv[0].size(); y++)
  366. cout << massiv[0][y] << " ";
  367. cout << endl;
  368. for(int m = massiv.size()-1; m >=1; m-=2)
  369. {
  370. for(int h = 0; h < dim; h++)
  371. parts[h] = 0;
  372. if(massiv[m].size()!=0){
  373. cout << "size" << massiv[m].size() << endl;
  374. secondCheck(podgr, massiv[m]);
  375. for(int h = 0; h < 10; h++)
  376. podgr2[h].clear();
  377. cout << "ok";
  378. /*for(int s = 0; s < 10; s++)
  379. for(int y = 0; y < podgr2[s].size(); y++)
  380. cout << podgr2[s][y];*/
  381. for(int s = 0; s < 10; s++)
  382. for(int y = 0; y < podgr[s].size(); y++)
  383. podgr2[s].push_back(podgr[s][y]);
  384. cout << "ok";
  385. for(int s = 0; s < 10; s++)
  386. for(int y = 0; y < podgr2[s].size(); y++)
  387. cout << podgr2[s][y];
  388. if(ex == 1){
  389. //return 0;
  390. cout <<"yes";
  391. }}
  392. }
  393. for(int u = 0; u < 10; u++)
  394. {
  395. for(int r = 0; r < podgr2[u].size(); r++)
  396. cout << podgr2[u][r] << " ";
  397. cout << endl;
  398. }
  399. }
  400. system("pause");
  401. return 0;
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement