Submission #7268193


Source Code Expand

Copy
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


const int MAX = 1000010;
int n;
int get(int a,int b){
  if(a < b)swap(a,b);
  return a * n + b;
}
vector<int> d[MAX];
int deg[MAX];
int res[MAX];
int wyn = 0;
int il = 0;
void add_edge(int a,int b){
  d[a].PB(b);
  deg[b]++;
}
void dfs(int v){
  if(deg[v] != 0)return;
  deg[v] = -1;
  il ++;
  maxi(wyn,res[v]);
  for(int el:d[v]){
    maxi(res[el], res[v] + 1);
    deg[el]--;
    dfs(el);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    vector<int> t(n - 1);
    R(j,n-1){
      cin >> t[j]; t[j]--;
    }
    R(j,n-2){
      add_edge(get(i,t[j]), get(i,t[j+1]));
    }
  }
  R(i,n*n)dfs(i);
  if(il != n * n){
    cout << "-1\n";
  }else{
    cout << wyn+1 << "\n";
  }
}

Submission Info

Submission Time
Task E - League
User Marcin
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2260 Byte
Status AC
Exec Time 221 ms
Memory 54272 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 13 ms 27008 KB
a02 AC 13 ms 27008 KB
a03 AC 13 ms 27008 KB
b04 AC 13 ms 27008 KB
b05 AC 13 ms 27008 KB
b06 AC 13 ms 27008 KB
b07 AC 13 ms 27008 KB
b08 AC 215 ms 54272 KB
b09 AC 170 ms 48768 KB
b10 AC 212 ms 54272 KB
b11 AC 221 ms 54272 KB
b12 AC 56 ms 37632 KB
b13 AC 49 ms 34688 KB
b14 AC 30 ms 31744 KB
b15 AC 26 ms 31104 KB
b16 AC 21 ms 30336 KB
b17 AC 17 ms 27776 KB
b18 AC 42 ms 33408 KB
b19 AC 38 ms 32640 KB
b20 AC 22 ms 30464 KB
b21 AC 19 ms 27904 KB
b22 AC 15 ms 27392 KB
b23 AC 14 ms 27136 KB