Submission #1065647

#TimeUsernameProblemLanguageResultExecution timeMemory
1065647EkinOnalZamjena (COCI18_zamjena)C++17
70 / 70
166 ms12368 KiB
//#pragma GCC optimize("O3,unroll-loops,Ofast") //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define MAX 200007 #define pb push_back #define mp make_pair #define int long long #define f first #define s second #define vi vector<int> #define pii pair<int,int> #define si set<int> #define vpii vector<pair<int,int>> const int mod = 1e9+7; const int INF = 1e18; // myMap.begin()->first : key // myMap.begin()->second : value int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;;b>>=1;}return ans;} int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;} int mul(int a,int b){return ((a%mod)*(b%mod))%mod;} int sum(int a,int b){return ((a%mod)+(b%mod))%mod;} //typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; map<string, string> par; map<string, int> sz; string find(string x){ if(par[x]==x) return x; return par[x]=find(par[x]); } bool unite(string a,string b){ a = find(a), b=find(b); if(a[0]<'a' && b[0]<'a') return a==b; if(a[0]<'a'){ par[b]=a; sz[a]+=sz[b]; return true; } else if(b[0]<'a'){ par[a]=b; sz[b]+=sz[a]; return true; } else if(a==b) return true; if(sz[a]<sz[b]) swap(a,b); sz[a]+=sz[b]; par[b]=a; return true; } void solve(){ int n; cin>>n; vector<string> a(n); for(int i=0;i<n;i++) {cin>>a[i];par[a[i]]=a[i];sz[a[i]]++;} vector<string> b(n); for(int i=0;i<n;i++) {cin>>b[i];par[b[i]]=b[i];sz[b[i]]++;} for(int i=0;i<n;i++){ if(!unite(a[i],b[i])) {cout<<"NE\n";return;} } cout<<"DA\n"; return; } int32_t main() { // freopen("hayfeast.in", "r", stdin); // freopen("hayfeast.out", "w", stdout); ios_base::sync_with_stdio(0);cin.tie(0); 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...