#include #include #include using namespace std; struct node_t { int id; string name; bool isFile; list children; node_t *parent; }; void register_path(node_t &root, string path, int &node_id) { int pos1 = 1, pos2; bool isFile, found; if (string::npos == (pos2 = path.find("/", pos1))) { isFile = true; } else { isFile = false; } found = false; for (list::iterator p = root.children.begin(); p != root.children.end(); p++) { if (p->name == path.substr(pos1, pos2-pos1)) { if (!isFile) { register_path(*p, path.substr(pos2), node_id); } found = true; break; } } if (!found) { node_t new_node; new_node.id = node_id; new_node.name = path.substr(pos1, pos2-pos1); new_node.isFile = isFile; new_node.children.clear(); new_node.parent = &root; node_id++; root.children.push_back(new_node); if (!isFile) { register_path(*(root.children.rbegin()), path.substr(pos2), node_id); } } } int search(node_t &root, string path) { int pos1 = 1, pos2; bool isLast; if (string::npos == (pos2 = path.find("/", pos1))) { isLast = true; } else { isLast = false; } if (path.substr(pos1, pos2-pos1) == ".") { if (root.isFile) { return -1; } if (isLast) { return -1; } return search(root, path.substr(pos2)); } if (path.substr(pos1, pos2-pos1) == "..") { if (root.parent == NULL) { return -1; } if (root.isFile) { return -1; } if (isLast) { return -1; } return search(*root.parent, path.substr(pos2)); } for (list::iterator p = root.children.begin(); p != root.children.end(); p++) { if (p->name == path.substr(pos1, pos2-pos1)) { if (isLast && p->isFile) { return p->id; } if (isLast && !p->isFile) { return -1; } if (!isLast) { return search(*p, path.substr(pos2)); } break; } } return -1; } void print(node_t &root, int depth) { for (int i = 0; i < depth-1; i++) { cout << "-"; } if (depth > 0) { cout << "+"; } cout << root.name; if (!root.isFile) { cout << "/"; } cout << "(" << root.id << ")"; cout << endl; for (list::iterator p = root.children.begin(); p != root.children.end(); p++) { print(*p, depth+1); } if (depth == 0) { cout << endl; } } int main() { int N, M, node_id; string input; while (true) { node_t root; root.id = 1; root.name = ""; root.isFile = false; root.children.clear(); root.parent = NULL; cin >> N >> M >> ws; if (N == 0 && M == 0) { break; } node_id = 2; for (int i = 0; i < N; i++) { getline(cin, input); register_path(root, input, node_id); } /* print(root, 0); */ for (int i = 0; i < M; i++) { string input1, input2; int result1, result2; getline(cin, input1); getline(cin, input2); /* cout << endl << "Start" << endl; */ if (input1[input1.length() - 1] != '/') { result1 = search(root, input1); if (result1 < 0) { result1 = search(root, input1 + "/index.html"); } } else { result1 = search(root, input1 + "index.html"); } if (input2[input2.length() - 1] != '/') { result2 = search(root, input2); if (result2 < 0) { result2 = search(root, input2 + "/index.html"); } } else { result2 = search(root, input2 + "index.html"); } /* cout << input1 << " : " << result1 << endl; cout << input2 << " : " << result2 << endl; */ if (result1 < 0 || result2 < 0) { cout << "not found" << endl; } else if (result1 == result2) { cout << "yes" << endl; } else if (result1 != result2) { cout << "no" << endl; } } } return 0; }