Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- typedef map<int, pair<bool, vector<int>* >* > MapLinks;
- typedef pair<int, pair<bool, vector<int>* >* > PairLink;
- typedef pair<bool, vector<int>* > PairNode;
- typedef vector<int>* Nodes;
- int main()
- {
- int N; // the total number of nodes in the level, including the gateways
- int L; // the number of links
- int E; // the number of exit gateways
- MapLinks links;
- MapLinks::iterator it;
- MapLinks::iterator it2;
- pair<bool, vector<int>* >* p;
- cin >> N >> L >> E; cin.ignore();
- for (int i = 0; i < L; i++) {
- int N1; // N1 and N2 defines a link between these nodes
- int N2;
- cin >> N1 >> N2; cin.ignore();
- it = links.find(N1);
- if(it == links.end()) {
- p = new PairNode(false, new vector<int>());
- it = (links.insert(PairLink(N1, p))).first;
- }
- it->second->second->push_back(N2);
- it = links.find(N2);
- if(it == links.end()) {
- p = new PairNode(false, new vector<int>());
- it = (links.insert(PairLink(N2, p))).first;
- }
- it->second->second->push_back(N1);
- }
- for (int i = 0; i < E; i++) {
- int EI; // the index of a gateway node
- cin >> EI; cin.ignore();
- links[EI]->first = true;
- }
- // print links
- for(it = links.begin(); it != links.end(); ++it) {
- cerr << it->first << " : " << it->second->first << endl;
- for(vector<int>::iterator ite = it->second->second->begin(); ite != it->second->second->end(); ++ite) {
- cerr << *ite << " ";
- }
- cerr << endl;
- }
- // game loop
- while (1) {
- int SI; // The index of the node on which the Skynet agent is positioned this turn
- cin >> SI; cin.ignore();
- cerr << "========" << endl << SI << endl;
- Nodes nodes;
- bool b = false;
- it = links.find(SI);
- if(it == links.end()) {
- continue;
- }
- nodes = it->second->second;
- for(vector<int>::iterator ite = nodes->begin(); ite != nodes->end(); ++ite) {
- *ite;
- it2 = links.find(*ite);
- if(it2 != links.end()) {
- if(it2->second->first) {
- cout << to_string(SI) << " " << to_string(*ite) << endl;
- b = true;
- break;
- }
- cerr << *ite << " : " << it2->second->first << endl;
- }
- }
- if(!b) {
- cout << to_string(SI) << " " << to_string(nodes->front()) << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement