#include<iostream> #include<queue> #include<list> #include<stdio.h> #include<vector> #include<map> #include<set> using namespace std; #define ull unsigned long long int #define FOR(i,n) for(int i=0;i<n;++i) #define FORD(i,n) for(int i=(n)-1;i>=0;--i) #define znakow 26 #define dcout 0 && cout #define INF 9999999 int inline min(int a,int b){return a>b?b:a;} int inline max(int a,int b){return a<b?b:a;} int NIL=0; int bfs(int n,int*pairU,int*pairV,list<int>*red,int*dist){ queue<int> q; FOR(u,n){ if(pairU[u]==NIL){ dist[u]=0; q.push(u); }else{ dist[u]=INF; } } dist[NIL]=INF; while(!q.empty()){ int u=q.front(); q.pop(); if(dist[u]<dist[NIL]){ //if(red[u]!=NULL) for(list<int>::iterator v=red[u].begin();v!=red[u].end();++v){ if(dist[pairV[*v]]==INF){ dist[pairV[*v]]=dist[u]+1; q.push(pairV[*v]); } } } } //dcout<<(dist[NIL]!=INF)<<endl; return dist[NIL]!=INF; } int dfs(int u, list<int>*red, int*pairU,int*pairV,int*dist){ if(u!=NIL){ //if(red[u]!=NULL) for(list<int>::iterator v=red[u].begin();v!=red[u].end();++v){ if(dist[pairV[*v]]==dist[u]+1){ if(dfs(pairV[*v],red,pairU,pairV,dist)){ pairV[*v]=u; pairU[u]=*v; return 1; } } } dist[u]=INF; return 0; } return 1; } int hopcroftKarp(int n,list<int>*red){ NIL=n+4; int*pairU=new int[n+11]; int*pairV=new int[n+11]; int*dist=new int[n+11]; FOR(i,n+11){pairU[i]=pairV[i]=NIL;} int m=0; while(bfs(n,pairU,pairV,red,dist)) FOR(i,n) if(pairU[i]==NIL) if(dfs(i,red,pairU,pairV,dist)) ++m; delete[] pairU,pairV,dist; return m; } int main(){//list<int>*x=new list<int>[3];x[1].push_back(6);cout<<x[1].front()<<endl;return 0; int tests; scanf("%d",&tests); FOR(test,tests){ int n,m; scanf("%d %d",&n,&m); if(m==0){ printf("REMIS\n"); continue; } //list<int>*green=new list<int>[n]; list<int>*red=new list<int>[n]; int*hr=new int[n]; int*hg=new int[n]; int*attacking=new int[n]; FOR(i,n)attacking[i]=0; FOR(i,n)hr[i]=0; FOR(i,n)hg[i]=0; FOR(i,m){ int a,b; char z; scanf("%d %c %d",&a,&z,&b); if(z=='<'){ red[a-1].push_back(b-1); //red[b-1].push_back(a-1); ++hr[a-1]; ++attacking[b-1]; }else{ //green[a-1].push_back(b-1); //green[b-1].push_back(a-1); ++hg[b-1]; } } int finish=0; FOR(i,n){ if(hg[i]==n){ printf("WYGRANA\n"); finish=1;break; } if(hr[i]==n){ printf("PRZEGRANA\n"); finish=1;break; } } delete[] hr; delete[] hg; if(!finish){ int allKill=1; FOR(i,n){ if(attacking[i]==0){ allKill=0;break; } } delete[] attacking; if(allKill){ printf("PRZEGRANA\n"); delete[] red; continue; } //int hk = hopcroftKarp(n,red); //dcout<<hk<<endl; //if(hk==n){ //printf("PRZEGRANA\n"); //}else{ printf("REMIS\n"); //} }else{ delete[] attacking;} delete[] red; //delete[] green; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #include<iostream> #include<queue> #include<list> #include<stdio.h> #include<vector> #include<map> #include<set> using namespace std; #define ull unsigned long long int #define FOR(i,n) for(int i=0;i<n;++i) #define FORD(i,n) for(int i=(n)-1;i>=0;--i) #define znakow 26 #define dcout 0 && cout #define INF 9999999 int inline min(int a,int b){return a>b?b:a;} int inline max(int a,int b){return a<b?b:a;} int NIL=0; int bfs(int n,int*pairU,int*pairV,list<int>*red,int*dist){ queue<int> q; FOR(u,n){ if(pairU[u]==NIL){ dist[u]=0; q.push(u); }else{ dist[u]=INF; } } dist[NIL]=INF; while(!q.empty()){ int u=q.front(); q.pop(); if(dist[u]<dist[NIL]){ //if(red[u]!=NULL) for(list<int>::iterator v=red[u].begin();v!=red[u].end();++v){ if(dist[pairV[*v]]==INF){ dist[pairV[*v]]=dist[u]+1; q.push(pairV[*v]); } } } } //dcout<<(dist[NIL]!=INF)<<endl; return dist[NIL]!=INF; } int dfs(int u, list<int>*red, int*pairU,int*pairV,int*dist){ if(u!=NIL){ //if(red[u]!=NULL) for(list<int>::iterator v=red[u].begin();v!=red[u].end();++v){ if(dist[pairV[*v]]==dist[u]+1){ if(dfs(pairV[*v],red,pairU,pairV,dist)){ pairV[*v]=u; pairU[u]=*v; return 1; } } } dist[u]=INF; return 0; } return 1; } int hopcroftKarp(int n,list<int>*red){ NIL=n+4; int*pairU=new int[n+11]; int*pairV=new int[n+11]; int*dist=new int[n+11]; FOR(i,n+11){pairU[i]=pairV[i]=NIL;} int m=0; while(bfs(n,pairU,pairV,red,dist)) FOR(i,n) if(pairU[i]==NIL) if(dfs(i,red,pairU,pairV,dist)) ++m; delete[] pairU,pairV,dist; return m; } int main(){//list<int>*x=new list<int>[3];x[1].push_back(6);cout<<x[1].front()<<endl;return 0; int tests; scanf("%d",&tests); FOR(test,tests){ int n,m; scanf("%d %d",&n,&m); if(m==0){ printf("REMIS\n"); continue; } //list<int>*green=new list<int>[n]; list<int>*red=new list<int>[n]; int*hr=new int[n]; int*hg=new int[n]; int*attacking=new int[n]; FOR(i,n)attacking[i]=0; FOR(i,n)hr[i]=0; FOR(i,n)hg[i]=0; FOR(i,m){ int a,b; char z; scanf("%d %c %d",&a,&z,&b); if(z=='<'){ red[a-1].push_back(b-1); //red[b-1].push_back(a-1); ++hr[a-1]; ++attacking[b-1]; }else{ //green[a-1].push_back(b-1); //green[b-1].push_back(a-1); ++hg[b-1]; } } int finish=0; FOR(i,n){ if(hg[i]==n){ printf("WYGRANA\n"); finish=1;break; } if(hr[i]==n){ printf("PRZEGRANA\n"); finish=1;break; } } delete[] hr; delete[] hg; if(!finish){ int allKill=1; FOR(i,n){ if(attacking[i]==0){ allKill=0;break; } } delete[] attacking; if(allKill){ printf("PRZEGRANA\n"); delete[] red; continue; } //int hk = hopcroftKarp(n,red); //dcout<<hk<<endl; //if(hk==n){ //printf("PRZEGRANA\n"); //}else{ printf("REMIS\n"); //} }else{ delete[] attacking;} delete[] red; //delete[] green; } return 0; } |