Contest Duration: - (local time) (150 minutes) Back to Home

Submission #7870169

Source Code Expand

Copy
```// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
#include "lib/dump.hpp"
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif
//}}}

int solve(){
int n;cin>>n;
vvi G(n);
rep(i,n){
string s;cin>>s;
rep(j, i+1, n){
if (s[j]=='1') {
G[i].pb(j);
G[j].pb(i);
}
}
}
dump(G);

int ans = -1;
rep(sv, n){
stack<int> st;
int k = 1;
st.push(sv);
bool valid = true;
vi level(n, -1);
level[sv] = 1;

while(true){
k++;
dump(sv, k);

stack<int> nst;
while(!st.empty()){
int v = st.top();st.pop();
each(to, G[v]){
if (level[to]==-1){
nst.push(to);
level[to] = k;
}
else if (level[to]==k or level[to]==k-2){
}
else{
dump(to, k, level[to], level);
valid = false;
}
}
}
if (!valid) break;

if (nst.empty()) break;
else{
st = nst;
}
}
dump(level);
// rep(i,n){
//   each(j, G[i]){
//     if (level[i]-level[j]!=1 and level[i]-level[j]!=-1)
//       valid = false;
//   }
// }
if (valid) chmax(ans, k-1);
}
cout << ans << endl;

return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
std::ifstream in(infile);
std::cin.rdbuf(in.rdbuf());
#endif
solve();
return 0;
} //}}}
```

#### Submission Info

Submission Time 2019-10-05 22:24:18+0900 B - Graph Partition kjnh10 C++14 (GCC 5.4.1) 500 2897 Byte AC 13 ms 640 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 3
 AC × 55
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 4 ms 256 KB
02.txt AC 3 ms 256 KB
03.txt AC 3 ms 256 KB
04.txt AC 4 ms 256 KB
05.txt AC 4 ms 256 KB
06.txt AC 4 ms 256 KB
07.txt AC 6 ms 256 KB
08.txt AC 4 ms 256 KB
09.txt AC 3 ms 256 KB
10.txt AC 3 ms 256 KB
11.txt AC 3 ms 256 KB
12.txt AC 3 ms 256 KB
13.txt AC 4 ms 256 KB
14.txt AC 4 ms 256 KB
15.txt AC 6 ms 256 KB
16.txt AC 3 ms 256 KB
17.txt AC 4 ms 256 KB
18.txt AC 4 ms 256 KB
19.txt AC 4 ms 256 KB
20.txt AC 4 ms 256 KB
21.txt AC 5 ms 256 KB
22.txt AC 6 ms 256 KB
23.txt AC 8 ms 256 KB
24.txt AC 4 ms 256 KB
25.txt AC 4 ms 256 KB
26.txt AC 4 ms 256 KB
27.txt AC 4 ms 256 KB
28.txt AC 4 ms 256 KB
29.txt AC 5 ms 256 KB
30.txt AC 7 ms 256 KB
31.txt AC 8 ms 256 KB
32.txt AC 4 ms 256 KB
33.txt AC 8 ms 256 KB
34.txt AC 8 ms 256 KB
35.txt AC 12 ms 640 KB
36.txt AC 13 ms 640 KB
37.txt AC 7 ms 512 KB
38.txt AC 7 ms 512 KB
39.txt AC 2 ms 256 KB
40.txt AC 2 ms 256 KB
41.txt AC 6 ms 256 KB
42.txt AC 6 ms 256 KB
43.txt AC 4 ms 256 KB
44.txt AC 8 ms 256 KB
45.txt AC 5 ms 256 KB
46.txt AC 6 ms 256 KB
47.txt AC 7 ms 256 KB
48.txt AC 6 ms 256 KB
49.txt AC 1 ms 256 KB
50.txt AC 1 ms 256 KB
51.txt AC 1 ms 256 KB
52.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB