Submission #107463

#TimeUsernameProblemLanguageResultExecution timeMemory
107463KalamZamjena (COCI18_zamjena)C++14
56 / 70
101 ms11252 KiB
// KALAM # include<bits/stdc++.h> using namespace std; const int N = 100000 + 77; int n , P[N]; string X[N] , Y[N]; vector < string > V; inline int GetId(string T) {return lower_bound(V.begin() , V.end() , T) - V.begin() + 1;} int Find(int x) {return P[x] <= 0 ? x : (P[x] = Find(P[x]));} inline void Merge(int v , int u) { v = Find(v); u = Find(u); if(v == u) return ; P[v] += P[u]; P[u] = v; } int main() { ios::sync_with_stdio(0);cin.tie(0); cin >> n; for(int i = 1;i <= n;++ i) cin >> X[i] , V.push_back(X[i]); for(int i = 1;i <= n;++ i) cin >> Y[i] , V.push_back(Y[i]); sort(V.begin() , V.end()); V.resize(unique(V.begin() , V.end()) - V.begin()); for(string S : V) if(S[0] <= '9' && S[0] >= '0') -- P[GetId(S)]; for(int i = 1;i <= n;++ i) Merge(GetId(X[i]) , GetId(Y[i])); for(int i = 1;i <= n;++ i) if(P[i] < - 1) return ! printf("NE\n"); printf("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...