Submission #471489

#TimeUsernameProblemLanguageResultExecution timeMemory
471489HossamHero7Zamjena (COCI18_zamjena)C++14
70 / 70
212 ms16080 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' map <string,vector<string>> adj; map <string,bool> vis; string curNum = "-1"; bool isNum(string s){ for(auto i : s){ if(i < '0' || i > '9') return 0; } return 1; } bool valid = 1; void dfs(string node){ vis[node] = 1; if(isNum(node) && curNum == "-1"){ curNum = node; } for(auto ch : adj[node]){ if(!isNum(ch) || curNum == ch || curNum == "-1"){ if(!vis[ch]) dfs(ch); } else valid = 0; } } void solve(){ int n; cin>>n; vector <string> v1(n); vector <string> v2(n); for(auto &i:v1) cin>>i; for(auto &i:v2) cin>>i; for(int i=0;i<n;i++){ adj[v1[i]].push_back(v2[i]); adj[v2[i]].push_back(v1[i]); } for(auto i : v1){ if(!vis[i]) dfs(i); if(!valid){ cout<<"NE"<<endl; return; } valid = 1; curNum = "-1"; } for(auto i : v2){ if(!vis[i]) dfs(i); if(!valid){ cout<<"NE"<<endl; return; } curNum = "-1"; } cout<<"DA"<<endl; } int main() { int t=1; // cin>>t; while(t--){ solve(); } 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...