Advertisement
TheTintin

Untitled

Apr 18th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. /**
  10. * Auto-generated code below aims at helping you parse
  11. * the standard input according to the problem statement.
  12. **/
  13.  
  14. typedef map<int, pair<bool, vector<int>* >* > MapLinks;
  15. typedef pair<int, pair<bool, vector<int>* >* > PairLink;
  16. typedef pair<bool, vector<int>* > PairNode;
  17. typedef vector<int>* Nodes;
  18.  
  19. int main()
  20. {
  21. int N; // the total number of nodes in the level, including the gateways
  22. int L; // the number of links
  23. int E; // the number of exit gateways
  24.  
  25. MapLinks links;
  26. MapLinks::iterator it;
  27. MapLinks::iterator it2;
  28. pair<bool, vector<int>* >* p;
  29.  
  30. cin >> N >> L >> E; cin.ignore();
  31. for (int i = 0; i < L; i++) {
  32. int N1; // N1 and N2 defines a link between these nodes
  33. int N2;
  34. cin >> N1 >> N2; cin.ignore();
  35.  
  36. it = links.find(N1);
  37. if(it == links.end()) {
  38. p = new PairNode(false, new vector<int>());
  39. it = (links.insert(PairLink(N1, p))).first;
  40. }
  41. it->second->second->push_back(N2);
  42.  
  43. it = links.find(N2);
  44. if(it == links.end()) {
  45. p = new PairNode(false, new vector<int>());
  46. it = (links.insert(PairLink(N2, p))).first;
  47. }
  48. it->second->second->push_back(N1);
  49.  
  50. }
  51.  
  52. for (int i = 0; i < E; i++) {
  53. int EI; // the index of a gateway node
  54. cin >> EI; cin.ignore();
  55. links[EI]->first = true;
  56. }
  57.  
  58. // print links
  59. for(it = links.begin(); it != links.end(); ++it) {
  60. cerr << it->first << " : " << it->second->first << endl;
  61.  
  62. for(vector<int>::iterator ite = it->second->second->begin(); ite != it->second->second->end(); ++ite) {
  63. cerr << *ite << " ";
  64. }
  65. cerr << endl;
  66. }
  67.  
  68. // game loop
  69. while (1) {
  70. int SI; // The index of the node on which the Skynet agent is positioned this turn
  71. cin >> SI; cin.ignore();
  72.  
  73. cerr << "========" << endl << SI << endl;
  74.  
  75. Nodes nodes;
  76. bool b = false;
  77.  
  78. it = links.find(SI);
  79. if(it == links.end()) {
  80. continue;
  81. }
  82.  
  83. nodes = it->second->second;
  84.  
  85. for(vector<int>::iterator ite = nodes->begin(); ite != nodes->end(); ++ite) {
  86. *ite;
  87. it2 = links.find(*ite);
  88. if(it2 != links.end()) {
  89. if(it2->second->first) {
  90. cout << to_string(SI) << " " << to_string(*ite) << endl;
  91. b = true;
  92. break;
  93. }
  94. cerr << *ite << " : " << it2->second->first << endl;
  95. }
  96. }
  97.  
  98. if(!b) {
  99. cout << to_string(SI) << " " << to_string(nodes->front()) << endl;
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement