Submission #100739

#TimeUsernameProblemLanguageResultExecution timeMemory
100739OrtZamjena (COCI18_zamjena)C++11
70 / 70
252 ms16376 KiB
#include<iostream> #include<string> #include<vector> #include<cctype> #include<map> #include<set> #define MAX 50005 using namespace std; int n; set<string> visited; map<string, vector<string> > M; string a[MAX]; string b[MAX]; void dfs(string s) { for(auto it:M[s]) { if(visited.find(it)!=visited.end()) continue; visited.insert(it); dfs(it); } } bool isnumber(string ss) { if(isdigit(ss[0])) return 1; return 0; } bool check() { int cnt = 0; for(auto it:visited) if(isnumber(it)) cnt++; if(cnt>1) return 0; return 1; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0;i<n;i++) cin >> a[i]; for(int i=0;i<n;i++) cin >> b[i]; for(int i=0;i<n;i++) { M[a[i]].push_back(b[i]); M[b[i]].push_back(a[i]); } set<string> v; for(int i=0;i<n;i++) { if(v.find(a[i])==v.end()) { dfs(a[i]); if(check()) { for(auto it:visited) v.insert(it); visited.clear(); } else { cout << "NE"; return 0; } } } cout << "DA"; return 0; }
#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...