diff --git a/STABLEMP.cpp b/STABLEMP.cpp new file mode 100644 index 0000000..4be1fc4 --- /dev/null +++ b/STABLEMP.cpp @@ -0,0 +1,81 @@ +#include +#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); + +using namespace std; + + vector stableMariage(vector> &menPref, vector> &womenPref) +{ + int n = menPref.size(); + vector> mapWM(n); + for (int i = 0; i < n; ++i) + mapWM[i].resize(n); + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + mapWM[i][ womenPref[i][j] ] = j; + vector womanMatch(n, -1); + vector manMatch(n, -1); + queue q; + for (int i = 0; i < n; ++i) + q.push(i); + while (!q.empty()) + { + int man = q.front(); + q.pop(); + for (int woman : menPref[man]) + { + if (womanMatch[woman] == -1) + { + womanMatch[woman] = man; + manMatch[man] = woman; + break; + } + else + { + int otherMan = womanMatch[woman]; + if (mapWM[woman][otherMan] > mapWM[woman][man]) + { + manMatch[otherMan] = -1; + q.push(otherMan); + womanMatch[woman] = man; + manMatch[man] = woman; + break; + } + } + } + } + + return manMatch; +} + +int main() { + IOS; + int t; + cin>>t; + while(t--) { + int n,temp; + cin>>n; + vector> menPref(n), womenPref(n); + for (int i = 0; i < n; ++i) { + womenPref[i].resize(n); + cin>>temp; + for (int j = 0; j < n; ++j) { + cin>>womenPref[i][j]; + womenPref[i][j]--; + } + } + for (int i = 0; i < n; ++i) { + menPref[i].resize(n); + cin>>temp; + for (int j = 0; j < n; ++j) { + cin>>menPref[i][j]; + menPref[i][j]--; + } + } + vector marriages = stableMariage(menPref,womenPref); + for (int i = 0; i < n; ++i) { + cout< +#define ull unsigned long long int + +using namespace std; + +//Program to find the nth catalan number + +ull catalan(ull n) { + ull c = 1; + for (int i = 0; i < n; ++i) { + c *= (2*n-i); + c /= (i+1); + } + c /= (n+1); + return c; +} + +int main() { + ull n; + cin>>n; + cout< +#define ull unsigned long long int + +using namespace std; + +//Program to find the nth fibonnaci number + +int main() { + ull n; + cin>>n; + ull t1,t2; + t1 = 1; + t2 = 1; + if(n==1 || n==2) { + cout<<1<