Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Permutation algo #174

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Algo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sort and bunary search
10 changes: 10 additions & 0 deletions Algorithm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
int main()
{ int a[100];
int k=a[0];
for(int i=0;i<100;i++)
{ if(a[i]>k)
k=a[i];
}
printf("%d",k);
}
1 change: 1 addition & 0 deletions Binary Search/16123004.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
l = [ 2,3,4,5,6,8]
// This is a code hehehe

n = len(l)
for i in n:
Expand Down
116 changes: 116 additions & 0 deletions Graph/Permutations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <cassert>
#include<complex>
#include <time.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg
typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef complex<double> base;
const int INF = 1000000000;
const int MAX = 100007;
const int MAXE = 5000;
const int MAXV = 20*20;
const int BASE = 1000000007;
const int MOD = 1000000007;
vector<int> g[MAX];
bool U[MAX];
VI A , B;
int P[MAX];
int Q[MAX];
void dfs(int v)
{
U[v] = 1;
A.push_back(P[v]);
B.push_back(Q[v]);
FOR(i,0,g[v].size())
{
if (!U[g[v][i]])
{
dfs(g[v][i]);
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
int t;
cin >> t;
FOR(tt,0,t)
{
int n , m;
cin >> n >> m;
FOR(i,0,n)
{
U[i] = 0;
g[i].clear();
}
FOR(i,0,n)
{
cin >> P[i];
}
FOR(i,0,n)
{
cin >> Q[i];
}
FOR(i,0,m)
{
int a , b;
scanf("%d%d" , &a , &b);
--a;--b;
g[a].push_back(b);
g[b].push_back(a);
}
bool ok = 1;
FOR(i,0,n)
{
if (!U[i])
{
A.clear();
B.clear();
dfs(i);
sort(ALL(A));
sort(ALL(B));
if (A != B) ok = 0;
}
}
if (ok)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
return 0;
}