Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
		"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		having := map[string]Entry{}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			name := buf[0]
			price, _ := strconv.Atoi(buf[1])
			having[name] = Entry{price, []string{}}
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			name_, price_ := buf_[0], INF
			if _, ok := having[name_]; ok {
				price_ = having[name_].price
			}
			having[name_] = Entry{price_, buf_[2:]}
		}
		scanner.Scan()
		fmt.Println(calculation(scanner.Text(), having))
	}
}

type Entry struct {
	price int
	elements []string
}

// メモ再帰的
func calculation(target string, having map[string]Entry) int {
	ans := INF
	if len(having[target].elements) > 0 {
		ans = 0
		for _, item := range having[target].elements {
			ans += calculation(item, having)
		}
	}
	return min(ans, having[target].price)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
  int itemn;
  int goldn;
  int goldnn;
  int f;
  int outp;
  string goldname;
  string goldpname;
  vector<int> outw;
  int lk;
  for(lk = 0; ;lk++){
    cin >> itemn;
    if(itemn == 0){
      break;
    }
    typedef struct item_s{
      vector<string> num;
      vector<int> price;
    }item_sd;
    item_sd item;
    item.num.resize(itemn);
    item.price.resize(itemn);

    for(int n = 0;n<itemn;n++){
      cin >> item.num[n];
      cin >> item.price[n];
    }
    cin >> goldn;
    for(int a = 0;a<goldn;a++){
      cin >> goldname;
      for(int z = 0;z<itemn;z++){
        if(item.num[z] == goldname){
          item.price[z] = 0;
          f = z;
        }
      }
      cin >> goldnn;
      for(int l = 0;l<goldnn;l++){
        cin >> goldpname;
        for(int z = 0;z<itemn;z++){
          if(item.num[z] == goldpname){
            item.price[f] += item.price[z];
          }
        }
      }
    }
    cin >> goldpname;
    for(int z = 0;z<itemn;z++){
      if(item.num[z] == goldpname){
        outw.resize(lk+1,item.price[z]);
      }
    }
  }
  for(int y = 0;y<lk;y++){
    cout << outw[y] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[101],d,f[101],g=1000001,h[101],j,i,k,q,w,e;
	char z[101][101],x[101][101],c[101][101][101],v[101];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			scanf("%s %d",z[i],&s[i]);
		}
		scanf("%d",&d);
		for(i=0;i<d;i++){
			scanf("%s %d",x[i],&f[i]);
			for(j=0;j<f[i];j++){
				scanf("%s",c[i][j]);
			}
			h[i]=0;
		}
		scanf("%s",v);
		for(i=0;i<a;i++) if(strcmp(v,z[i])==0) if(g>s[i]) g=s[i];
		for(i=0;i<d;i++){
			for(j=0;j<d;j++){
				for(k=0;k<f[j];k++){
					if(strcmp(x[i],c[j][k])==0) h[j]++;
				}
			}
		}
		if(d!=0){
			while(1){
				for(i=0;i<d;i++){
					q=0;
					w=0;
					e=0;
					if(h[i]==0){
						for(j=0;j<a;j++){
							for(k=0;k<f[i];k++){
								if(strcmp(z[j],c[i][k])==0){
									q+=s[j];
									break;
								}
							}
						}
						for(j=0;j<a;j++){
							if(strcmp(z[j],x[i])==0){
								if(s[j]>q){
									s[j]=q;
									q=0;
									break;
								}
							}
						}
					}
					h[i]--;
				}
				for(i=0;i<d;i++){
					if(h[i]<0) w++;
				}
				if(w==d) break;
			}
		}
		for(i=0;i<a;i++){
			if(strcmp(v,z[i])==0){
				printf("%d\n",s[i]);
				break;
			}
		}
	}
	return 0;
}

C++: 
#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
  int n, m;
  string s, s2;
  int k;
  map<string, int> cost;

  while(cin>>n, n){
    cost.clear();
    while(n-- > 0){
      cin>>s>>k;
      cost[s] = k;
    }
    cin>>n;
    while(n-- > 0){
      cin>>s>>m;
      k = 0;
      while(m-- > 0){
	cin>>s2;
	k += cost[s2];
      }
      if(cost[s] > k) cost[s] = k;
    }
    cin>>s;
    cout<<cost[s]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

map<string, int> v;
map<string, vector<string> > l;

int main()
{
	int n;
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			string str;
			int p;
			cin >> str >> p;
			v[str] = p;
		}
		
		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; i++){
			string o;
			int k;
			cin >> o >> k;
			for (int j = 0; j < k; j++){
				string q;
				cin >> q;
				l[o].push_back(q);
			}
		}
		
		for (int k = 0; k < 100; k++){
		//while (true){
			bool update = false;
			
			typedef map<string, vector<string> >::iterator ite;
			for (ite i = l.begin(); i != l.end(); ++i){
				int sum = 0;
				for (int j = 0; j < (*i).second.size(); j++){
					sum += v[(*i).second[j]];
				}
				if (v[(*i).first] > sum){
					v[(*i).first] = sum;
					update = true;
				}
			}
			
		//	if (!update) break;
		}
		
		string t;
		cin >> t;
		cout << v[t] << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(cin >> n , n){
        map<string,int> id;
        vector<int> p(n);
        for(int i=0;i<n;i++){
            string s;
            cin >> s >> p[i];
            id[s] = i;
        }
        int m;
        cin >> m;
        vector<pair<int,vector<int> > > recipe(m);
        for(int i=0;i<m;i++){
            string o;
            int k;
            vector<int> ls;
            cin >> o >> k;
            for(int j=0;j<k;j++){
                string q;
                cin >> q;
                ls.push_back(id[q]);
            }
            recipe[i] = make_pair(id[o],ls);
        }
        bool update = true;
        while(update){
            update = false;
            for(int i=0;i<m;i++){
                int sum = 0;
                for(auto j : recipe[i].second){
                    sum += p[j];
                }
                if(p[recipe[i].first] > sum){
                    p[recipe[i].first] = sum;
                    update = true;
                }
            }
        }
        string t;
        cin >> t;
        cout << p[id[t]] << endl;
    }
    return 0;
}