Submission #7266266


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vvl order(n,vl(n-1));
	FOR(i,0,n) FOR(j,0,n-1) {
		ll x; cin >> x;
		order[i][j] = x-1;
	}
	
	auto id = [&](ll i, ll j) {
		if (i > j) swap(i,j);
		return i*n+j;
	};
	
	vl indeg(n*n);
	vvl adj(n*n);
	FOR(i,0,n) {
		FOR(k,0,n-2) {
			ll a = id(i,order[i][k]);
			ll b = id(i,order[i][k+1]);
			adj[a].pb(b);
			indeg[b]++;
		}
	}
	
	vl depth(n*n);
	queue<ll> q;
	FOR(a,0,n*n) if (!indeg[a]) q.push(a);

	while (sz(q)) {
		ll a = q.front();
		q.pop();
		for (ll b: adj[a]) {
			depth[b] = max(depth[b], depth[a]+1);
			if (!--indeg[b]) q.push(b);
		}
	}

	ll res = *max_element(all(depth)) + 1;
	if (accumulate(all(indeg),0LL)) res = -1;
	cout << res << endl;
}

Submission Info

Submission Time
Task E - League
User pwild
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1377 Byte
Status AC
Exec Time 257 ms
Memory 66944 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 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 244 ms 66944 KB
b09 AC 196 ms 66944 KB
b10 AC 257 ms 66816 KB
b11 AC 239 ms 66688 KB
b12 AC 57 ms 19072 KB
b13 AC 48 ms 16256 KB
b14 AC 21 ms 7936 KB
b15 AC 17 ms 5888 KB
b16 AC 10 ms 3840 KB
b17 AC 6 ms 2176 KB
b18 AC 40 ms 12672 KB
b19 AC 31 ms 10368 KB
b20 AC 11 ms 4096 KB
b21 AC 8 ms 2688 KB
b22 AC 4 ms 1408 KB
b23 AC 2 ms 640 KB