23dfcca431 2011-02-23 kinaba: //------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: // ID Assignment 23dfcca431 2011-02-23 kinaba: // 23dfcca431 2011-02-23 kinaba: // Verified by 23dfcca431 2011-02-23 kinaba: // - ACM/ICPC Tokyo 2010 A 23dfcca431 2011-02-23 kinaba: // - SRM 491 Div1 LV3 23dfcca431 2011-02-23 kinaba: //------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: template<typename T> 23dfcca431 2011-02-23 kinaba: class IdGen 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: map<T, int> v2id_; 23dfcca431 2011-02-23 kinaba: vector<T> id2v_; 23dfcca431 2011-02-23 kinaba: public: 23dfcca431 2011-02-23 kinaba: int v2id(const T& v) { 23dfcca431 2011-02-23 kinaba: if( !v2id_.count(v) ) { v2id_[v] = size(); id2v_.push_back(v); } 23dfcca431 2011-02-23 kinaba: return v2id_[v]; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: const T& id2v(int i) const { return id2v_[i]; } 23dfcca431 2011-02-23 kinaba: int size() const { return id2v_.size(); } 23dfcca431 2011-02-23 kinaba: };