Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if 1
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <string>
- #include <vector>
- #include <list>
- #include <map>
- #include <unordered_map>
- #include <set>
- #include <unordered_set>
- #include <queue>
- #include <deque>
- #include <bitset>
- #include <algorithm>
- #include <cmath>
- typedef long long ll;
- typedef unsigned long long ull;
- #define ff first
- #define ss second
- using namespace std;
- const ull hashConst = 111;
- const ull ullMax = 18446744073709551615UL;
- class Project{
- public:
- string name;
- ull version;
- Project(){
- this->name = "";
- this->version = -1;
- }
- Project (string& name, ull vers){
- this->name = name;
- this->version = vers;
- subs = vector<Project*>(0);
- }
- vector<Project*> subs;
- void addSub(Project* sub){
- subs.push_back(sub);
- }
- bool operator ==(const Project& other){
- return this->name == other.name && this->version == other.version;
- }
- };
- int main() {
- ull projectsCount;
- cin >> projectsCount;
- unordered_map<string, unordered_map<ull, Project*>> projects_by_versions;
- Project* ptr_pproj;
- for (ull i = 0; i < projectsCount; i++){
- string pname;
- ull pvers;
- cin >> pname >> pvers;
- Project * ptr_proj = projects_by_versions[pname][pvers];
- if ( ptr_proj == NULL){
- ptr_proj = new Project(pname, pvers);
- projects_by_versions[pname][pvers] = ptr_proj;
- }
- ull subCount;
- cin >> subCount;
- for (ull j = 0; j < subCount; j++){
- string sname;
- ull svers;
- cin >> sname >> svers;
- Project * ptr_sub = projects_by_versions[sname][svers];
- if (ptr_sub == NULL){
- ptr_sub= new Project(sname, svers);
- projects_by_versions[sname][svers] = ptr_sub;
- }
- ptr_proj->addSub(ptr_sub);
- }
- if(i == 0){
- ptr_pproj = ptr_proj;
- }
- }
- map <string, pair<ull, ull>* > psubs;
- queue<Project*> q;
- unordered_map<Project*, bool> isEntered;
- q.push(ptr_pproj);
- ull dist = 1;
- while(q.size() ){
- Project* curv = q.front();
- q.pop();
- for (Project* sub : curv->subs){
- if (!isEntered[sub]){
- q.push(sub);
- pair<ull, ull> * psub = psubs[sub->name];
- if ( (psub == NULL) ){
- psub = new pair<ull, ull>(dist, sub->version);
- psubs[sub->name] = psub;
- }
- else if (psub->first > dist ||
- (psub->first == dist && psub->second > sub->version )){
- psubs[sub->name] = psub;
- }
- }
- }
- isEntered[curv] = true;
- dist++;
- }
- for (auto s : psubs){
- cout << s.first << " " << s.second->second << endl;
- }
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement