#include #include #include using namespace std; struct strCmp { bool operator()( const char* s1, const char* s2 ) const { return strcmp( s1, s2 ) < 0; } }; struct Node { char nazev[5]; int nextCount; Node * next[40005]; double nextNasobitel[40005]; double nasobitel; }; Node nodes[205]; int nodesCount = 0; int loadNazvy() { scanf("%d", &nodesCount); if(nodesCount == 0) return 0; map meny; for(int i = 0; i < nodesCount; i++) { scanf("%s", nodes[i].nazev); meny[nodes[i].nazev] = &nodes[i]; nodes[i].nasobitel = -1; // nulování nodes[i].nextCount = 0; } int hran; char nazev1[5]; char nazev2[5]; int jmenovatel; int citatel; Node * current; scanf("%d", &hran); for(int i = 0; i < hran; i++) { scanf("%s %s %d:%d", nazev1, nazev2, &jmenovatel, &citatel); current = meny[nazev1]; current->next[current->nextCount] = meny[nazev2]; current->nextNasobitel[current->nextCount] = (double)citatel / jmenovatel; current->nextCount++; } return 1; } int pocitej() { for(int gl = 0; gl < nodesCount; gl++) { Node * start = &nodes[gl]; start->nasobitel = 1.0f; int pocetDosazeno = 1; Node* dosazeno[40005]; dosazeno[0] = start; for(int i = 0; i < nodesCount; i++) { if(gl != i) { nodes[i].nasobitel = -1.0f; } } while(pocetDosazeno > 0) { pocetDosazeno--; Node * current = dosazeno[pocetDosazeno]; for(int i = 0; i < current->nextCount; i++) { float hodnota = current->nasobitel * current->nextNasobitel[i]; if(current->next[i]->nasobitel < hodnota) { current->next[i]->nasobitel = hodnota; dosazeno[pocetDosazeno] = current->next[i]; pocetDosazeno++; if(current->next[i] == start) return 1; } } } } return 0; } int main() { while(loadNazvy()) { //printf("\n\n"); if(pocitej()) printf("Arbitrage\n"); else printf("Ok\n"); } return 0; }