Example #1
0
int main() {
    Graph G;
	string input;
	int opcode;
	string ver1;
	string ver2;
	int weigh;
	cin>>input;
	while(input!="END"){
		G.vertices.push_back(input);
		cin>>input;
	}
	cin>>input;
	while(input!="END"){
		ver1=input;
		cin>>input;
		ver2=input;
		cin>>weigh;
		if(G.FindVertex(ver1)==1 && G.FindVertex(ver2)==1){
			G.AddEdge(ver1,ver2,weigh);
		}
		cin>>input;
	}
	//G.PrintOut();
	cin>>opcode;
	while(opcode!=0){
		if(opcode==1){
			cin>>ver1;
			cout<<G.FindVertex(ver1)<<endl;
		}
		else{
int main() {

    Graph G;
    string input;
    cin >> input;
    while(input != "END") {
        G.vertices.push_back(input);
        cin >> input;
    }
    string first, second;
    cin >> first;
    int weight;
    while(first != "END") {
        cin >> second;
        cin >> weight;
        G.AddEdge(first,second,weight);
        cin >> first;
    }
    //G.PrintOut();
    int opcode;
    cin >> opcode;
    string A, B;
    while(opcode != 0) {
        switch(opcode)
        {
        case 1:
            cin >> A;
            if(G.FindVertex(A))
                cout << 1 << endl;
            else
                cout << 0 << endl;
        break;
        case 2:
            cin >> A;
            cin >> B;
            cout << G.FindEdgeCost(A, B) << endl;
            break;
        case 3:
            cin >> A;
            cin >> B;
            cout << G.IsReachable(A, B) << endl;
            break;
        }
        cin >> opcode;
    }
}
int main ()
{
    Graph G;

    string temp;
    cin >> temp;

    while (temp != "END")
    {
        if (!G.FindVertex(temp))
        {
            G.vertices.push_back(temp);
        }
        cin >> temp;
    }

    string key1, key2;
    int val;
    cin >> key1;

    while (key1 != "END")
    {
        cin >> key2; cin >> val;

        if (G.FindVertex(key1) && G.FindVertex(key2))
        {
            G.AddEdge(key1, key2, val);
        }

        cin >> key1;
    }

    int n;
    cin >> n;

    while (n != 0)
    {
        switch (n)
        {
            case 1:
            {
                string param;
                cin >> param;
                if (G.FindVertex(param)) cout << "1" << endl;
                else cout << "0" << endl;
                break;
            }
            case 2:
            {
                string param1, param2;
                cin >> param1; cin >> param2;
                cout << G.FindEdgeCost(param1, param2) << endl;
                break;
            }
            case 3:
            {
                string param1, param2;
                cin >> param1; cin >> param2;
                cout << G.IsReachable(param1, param2) << endl;
                break;
            }
        }

        cin >> n;
    }

    return 1;
}