NBUT 1554 Lord of Minecraft

来源:互联网 发布:apache mime类型 json 编辑:程序博客网 时间:2024/03/29 23:52

请不要随便指点别人该怎么做、每个人的人生都应该自己掌握、你给不了别人一切、你也不懂别人的忧伤、

                                                                                          微笑不代表快乐、哭泣不一定悲伤

               不努力怎么让关心你的人幸福、不努力怎么让看不起你的人绝望、

                                                                                                                                    

                                                                                                                                                              我用生命在奋斗——lx_Zz

—————————————————————————————————————————————————————————————

—————————————————————————    华丽的分割线    ————————————————————————————

—————————————————————————————————————————————————————————————

140448DreamofFinal70312161443G++2014-05-09 11:26:07

我要被自己恶心死了、、、怎么写都不对、上次直接BFS因为数据加强被挂掉了、然后重新写、一写几个小时、

一定是因为昨晚睡太晚了、所以怎么写都不对、、好蛋疼、

# include <cstdio># include <cstring># include <string># include <map># include <vector>using namespace std;const int maxn = 10005;int n, m;map <string, int> mp;vector <int> G[maxn];int d[maxn];int l[maxn], r[maxn];int id, root;char sx[15], sy[15];int cnt;int head[maxn];struct node{int to,next;}edge[maxn];int k;void add(int x,int y){edge[k].to=y;edge[k].next=head[x];head[x]=k++;}void dfs(int cur, int depth){    d[cur] = depth;    l[cur] = cnt++;    for(int i=head[cur];i!=-1;i=edge[i].next)dfs(edge[i].to,depth+1);    r[cur] = cnt++;}int add(const string &s){    return mp[s]>0 ? mp[s]:(mp[s]=++id);}void init(void){k=0;memset(head,-1,sizeof(head));    id = 0;    mp.clear();    for (int i = 1; i <= n+1; ++i) G[i].clear();    for (int i = 0; i < n; ++i) {        scanf("%s%s", sx, sy);         int x = add(sx), y = add(sy);        if (strcmp(sy, "Hungar") == 0) root = y;        add(y,x);    }    cnt = 0;    dfs(root, 0);}void solve(void){    int ans = 0;    for (int i = 0; i < m; ++i) {        scanf("%s%s", sx, sy);        stx = sx, sty = sy;        int x = mp[stx];        int y = mp[sty];        if ((d[x]<d[y] && !(l[x]<l[y] && r[y]<r[x])) || (d[x]==d[y])) ++ans;    }    printf("%d\n", ans);}int main(){    while (EOF != scanf("%d%d", &n, &m)) {        init();        solve();    }    return 0;}


0 0