Submission #1084337

#TimeUsernameProblemLanguageResultExecution timeMemory
1084337BlueGlaucus1Zamjena (COCI18_zamjena)C++17
70 / 70
139 ms16084 KiB
#include <iostream> #include <string> #include <map> #include <vector> using namespace std; map<string, vector<string> > con; map<string, bool> visited; int dfs(string s){ int curr_val = 0; if(isdigit(s[0])){ curr_val = stoi(s); } visited[s] = 1; for(int i = 0; i <con[s].size();i++){ string val = con[s][i]; if(visited[val]){ continue; } int cor = dfs(val); if(cor == -1){ return -1; } else if (cor ==0){ continue; } else if (curr_val==0){ curr_val = cor; }else if (curr_val!=cor){ return -1; } } return curr_val; } int main(){ int n; cin >> n; string arr[n]; string brr[n]; for(int i =0; i <n;i++){ cin >> arr[i]; } for(int i =0; i <n;i++){ cin >> brr[i]; } for(int i =0; i <n;i++){ con[arr[i]].push_back(brr[i]); con[brr[i]].push_back(arr[i]); } for(int i = 0; i <n;i++){ if(!visited[arr[i]]){ int g = dfs(arr[i]); if(g==-1){ cout <<"NE"; return 0; } } } cout << "DA"<<'\n'; return 0; }

Compilation message (stderr)

zamjena.cpp: In function 'int dfs(std::string)':
zamjena.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i <con[s].size();i++){
      |                    ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...