Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==================================================================//
- // Name : flash7even //
- // Author : Tarango Khan //
- // Codeforces : flash_7 //
- // Topcoder : flash_7 //
- // Hackerrank : flash_7 //
- // Email : tarangokhan77@gmail.com //
- // Facebook : flash7even //
- //==================================================================//
- //==================================================================//
- #include <bits/stdc++.h> //
- using namespace std; //
- #define read(nm) freopen(nm, "r", stdin) //
- #define write(nm) freopen(nm, "w", stdout) //
- #define pb push_back //
- #define MP make_pair //
- #define ff first //
- #define ss second //
- #define FABS(x) ((x)+eps<0?-(x):(x)) //
- #define POPCOUNT __builtin_popcountll //
- #define RIGHTMOST __builtin_ctzll //
- #define LEFTMOST(x) (63-__builtin_clzll((x))) //
- #define NUMDIGIT(x,y) (((int)(log10((x))/log10((y))))+1) //
- #define SQ(x) ((x)*(x)) //
- #define pf printf //
- #define sf scanf //
- #define phl printf("hello\n") //
- #define SZ(x) ((int)(x).size()) //
- #define mems(x,v) memset(x,v,sizeof(x)) //
- #define CLR(x,y) memset(x,y,sizeof(x)) //
- #define ALL(x) (x).begin(),(x).end() //
- #define NORM(x) if(x>=mod)x-=mod; //
- #define MOD(x,y) (((x)*(y))%mod) //
- #define fills(v,n) fill(v.begin(), v.end(), n) //
- #define LL long long //
- #define LLU long long unsigned int //
- #define vlong long long //
- #define uvlong unsigned long long //
- #define debug1(v1) cout<<"1@ Debug Val 1 = "<<v1<<endl; //
- #define debug2(v2) cout<<" 2@ Debug Num 2 = "<<v2<<endl; //
- #define debug3(v3) cout<<" 3@ Debug Res 3 = "<<v3<<endl; //
- #define UB(v,a) upper_bound(v.begin(),v.end(),a)-v.begin() //
- #define LB(v,a) lower_bound(v.begin(),v.end(),a)-v.begin() //
- #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL) //
- //==================================================================//
- //==================================================================//
- void make_unique(vector<int> &a){ sort(a.begin(), a.end()); //
- a.erase(unique(a.begin(), a.end()), a.end()); } //
- void printDouble(double f,int p){ cout << fixed; //
- cout << setprecision(p) << f <<endl; } //
- int Set(int N,int cur){ return N = N | (1<<cur); } //
- int Reset(int N,int cur){ return N = N & ~(1<<cur); } //
- bool Check(int N,int cur){ return (bool)(N & (1<<cur)); } //
- LL GCD(LL a,LL b){ if(b == 0) return a; return GCD(b,a%b);} //
- LL LCM(LL a,LL b){ return a*b/GCD(a,b);} //
- LL POW(LL a,LL p){ LL res = 1,x = a;while(p){if(p&1) //
- res = (res*x); x = (x*x);p >>= 1;} return res;} //
- //==================================================================//
- //==================================================================//
- //int knightDir[8][2] = {{-2,1},{-1,2},{1,2},{2,1}, //
- // {2,-1},{-1,-2},{1,-2},{-2,-1}}; //
- //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1}, //
- // {-1,-1},{1,1},{1,-1},{-1,1}}; //
- //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; //
- //==================================================================//
- #ifdef forthright48
- #include <ctime>
- clock_t tStart = clock();
- #define debug(args...) {dbg,args; cerr<<endl;}
- #define timeStamp printf("Exc Time: %.2fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC)
- #else
- #define debug(args...)
- #define timeStamp
- #endif
- struct debugger{
- template<typename T> debugger& operator , (const T& v){
- cerr << v << " ";
- return *this;
- }
- }dbg;
- typedef pair <LL,LL> pll;
- typedef vector<pll> vll;
- typedef vector<LL> vl;
- const LL inf = 2147383647;
- const LL MOD = 1000000007;
- const double pi = 2*acos(0.0);
- const double eps = 1e-9;
- //=======// Done With The Shortcut Stuffs! Now Let's Code! //=======//
- #define INF 100000000
- #define MAX 100005
- int N, M, E, R, C;
- // N = Maximum number of matching possible from left set.
- vector< int > Graph[MAX];
- int Left[MAX];
- int Right[MAX];
- int dist[MAX];
- int lCnt = 0,rCnt = 0;
- // lCnt = is max number of elements in left set.
- // rCnt = is max number of elements in right set.
- bool BFS() {
- queue< int > Q;
- for(int i = 1; i<=N; i++) {
- if(Left[i] == 0) {
- dist[i] = 0;
- Q.push(i);
- } else {
- dist[i] = INF;
- }
- }
- dist[0] = INF;
- while(!Q.empty()) {
- int u = Q.front(); Q.pop();
- if(u != 0) {
- int len = Graph[u].size();
- for(int i = 0; i<len; i++) {
- int v = Graph[u][i];
- if(dist[Right[v]] == INF) {
- dist[Right[v]] = dist[u] + 1;
- Q.push(Right[v]);
- }
- }
- }
- }
- return (dist[0] != INF);
- }
- bool DFS(int u) {
- if(u != 0) {
- int len = Graph[u].size();
- for(int i = 0; i<len; i++) {
- int v = Graph[u][i];
- if(dist[Right[v]] == dist[u]+1) {
- if(DFS(Right[v])) {
- Right[v] = u;
- Left[u] = v;
- return true;
- }
- }
- }
- dist[u] = INF;
- return false;
- }
- return true;
- }
- int hopcroft_karp() {
- int matching = 0;
- mems(Left,0);
- mems(Right,0);
- N = lCnt;
- while(BFS()){
- for(int i = 1; i<=N; i++){
- if(Left[i] == 0 && DFS(i)){
- matching++;
- }
- }
- }
- return matching;
- }
- int NN,MM;
- int A[100005];
- int st[100005];
- int ed[100005];
- void build_Graph(){
- for(int i = 1;i<=NN;i++){
- for(int j = 1;j<=MM;j++){
- LL L = 44LL*st[j];
- LL R = 44LL*ed[j];
- LL cur = 28LL*A[i];
- if(cur>=L && cur<=R){
- Graph[i].pb(j+NN);
- //pf("Edge %d-%d\n",i,j);
- }
- }
- }
- }
- int main(){
- //fast_cin;
- #ifdef forthright48
- //read("input.txt");
- //write("output.txt");
- #endif //forthright48
- int u,v,nCase;
- sf("%d",&nCase);
- for(int cs = 1;cs<=nCase;cs++){
- sf("%d",&NN);
- lCnt = NN+MM+5;
- for(int i = 1;i<=NN;i++){
- sf("%lld",&A[i]);
- }
- for(int i = 0;i<=lCnt;i++){
- Graph[i].clear();
- }
- sf("%d",&MM);
- for(int i = 1;i<=MM;i++){
- sf("%lld %lld",&st[i],&ed[i]);
- if(st[i]>ed[i]){
- swap(st[i],ed[i]);
- }
- }
- build_Graph();
- int ans = hopcroft_karp();
- printf("%d\n",ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement