Submission #197849

#TimeUsernameProblemLanguageResultExecution timeMemory
197849triplem5dsZamjena (COCI18_zamjena)C++14
70 / 70
408 ms29664 KiB
#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include "bits/stdc++.h" using namespace std; #define pb push_back #define F first #define S second #define f(i,a,b) for(int i = a; i < b; i++) #define endl '\n' using ll = long long; using db = long double; using ii = pair<int, int>; const int N = 1e5 + 5, LG = 19, MOD = 1e9 + 7; const int SQ =320; const long double EPS = 1e-7; bool isVar(string s){ if(isdigit(s[0]))return false; return true; } map<string, set<string> > mt; map<string, set<string> > adj; set<string> vis; set<string> kk; void dfs(string node){ if(vis.count(node)) return; vis.insert(node); for(auto x : mt[node])kk.insert(x); for(auto to : adj[node]){ dfs(to); } } int32_t main(){ #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; vector<string> vs1(n), vs2(n); f(i,0,n)cin >> vs1[i]; f(i,0,n)cin >> vs2[i]; vector<string> vt; f(i,0,n){ if(isVar(vs1[i]))vt.pb(vs1[i]); if(isVar(vs2[i]))vt.pb(vs2[i]); if(vs1[i] != vs2[i]){ if(isVar(vs1[i]) && isVar(vs2[i])){ adj[vs1[i]].insert(vs2[i]); adj[vs2[i]].insert(vs1[i]); } else if(isVar(vs1[i])){ mt[vs1[i]].insert(vs2[i]); } else if(isVar(vs2[i])){ mt[vs2[i]].insert(vs1[i]); } else { cout << "NE\n"; return 0; } } } sort(vt.begin(),vt.end()); vt.resize(unique(vt.begin(),vt.end())-vt.begin()); for(auto var : vt){ kk.clear(); dfs(var); if(kk.size() > 1){ cout << "NE\n"; return 0; } } cout << "DA\n"; 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...