Uva Foreign Exchange map 映射

来源:互联网 发布:it软件测试工程师 编辑:程序博客网 时间:2024/05/12 03:50

//注意每两个城市之间有两条有向边,城市可以为奇数比如说五个

//遍历map使用迭代,it->first,it->second

//啃了两个半小时,处理细节

#include<iostream>
#include<cstdio>
#include<set>
#include<vector>
#include<map>
using namespace std;
map<int,map<int,int> > mp;
int main(){
    int a,b,c;
    while(cin>>a&&a){
        mp.clear();
        for(int i=0;i<a;i++){
            cin>>b>>c;
            int jud=0;
            if(mp[c].count(b)&&mp[c][b]!=0){
                mp[c][b]--;
                jud=1;
            }
            if(!mp[b].count(c))
                mp[b][c]=0;
            if(!jud) mp[b][c]++;
        }
        for(map<int,map<int,int> >::iterator it=mp.begin();it!=mp.end();it++){
            map<int,int> it1=it->second;
            for(map<int,int>::iterator it2=it1.begin();it2!=it1.end();it2++){
                if(it2->second!=0){
                    cout<<"NO"<<endl;
                    goto label;
                }
            }
        }
        cout<<"YES"<<endl;
        label:;
    }
    return 0;
}

0 0
原创粉丝点击