Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- static const double eps = 1e-5;
- static const int INFTY = (1<<21);
- static const ll LLINFTY = (1LL<<53);
- #define REP(i,m,n) for(int i=m;i<int(n);i++)
- #define rep(i,n) REP(i,0,n)
- #define MAX (10000)
- bool dp[31][MAX+1];
- int V;
- vector<string> arc;
- class AllCycleLengths {
- public:
- void solve(int v){
- memset(dp,0,sizeof(dp));
- dp[v][0] = true;
- for(int c=0;c<MAX;c++){
- for(int id=0;id<V;id++){
- if( !dp[id][c] ) continue;
- for(int nex = 0;nex<V;nex++){
- if( arc[id][nex] == 'Y' )
- dp[nex][c+1] = true;
- }
- }
- }
- }
- string findAll(vector <string> arcs) {
- string res="";
- V = arcs.size();
- arc = arcs;
- string vc = string(MAX-1,'0');
- for(int v=0;v<V;v++){
- solve(v);
- for(int i=1;i<MAX;i++){
- if( dp[v][i] )
- vc[i-1] = '1';
- }
- }
- string comp = "1";
- bool f = false;
- for(int cc=0;cc<V;cc++){
- int cnt = 0;
- int be=0;
- for(int i=0;i<(int)vc.size()-cc;i++){
- if( vc.substr(i,cc+1) == comp ){
- if( cnt == 0 ) be = i;
- i+=cc;
- cnt++;
- }
- else cnt = 0;
- if( cnt == V+1 ){
- f=true;
- if( be ) res = vc.substr(0,be);
- res += "(" + comp + ")";
- }
- }
- comp = "0" + comp;
- if( res != "" ) break;
- }
- if(!f) res = "(0)";
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement