Cod sursa(job #2518728)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 6 ianuarie 2020 14:59:06
Problema Cutii Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <fstream>
#include <vector>
#include <iostream>
#include <cstring>
using namespace std;

ifstream fin("cutii.in");
ofstream fout("cutii.out");

struct cutie {
    int x, y, z;
    bool operator<(const cutie &other) const {
        return x < other.x && y < other.y && z < other.z;
    }
} v[3510];

int n, t, res;
vector <int> g[3510];
bool visited[3510];

int lungime(int x) {
    int ret = 1;
    if(g[x].size())
        for(int i = 0; i < g[x].size(); i++)
            ret = max(ret, 1+lungime(g[x][i]));
    return ret;
}

void solve() {
    while(t--) {
        for(int i = 1; i <= n; i++)
            fin >> v[i].x >> v[i].y >> v[i].z;

        for(int i = 1; i <= n; i++) {
            g[i].clear();
            for(int j = 1; j <= n; j++)
                if(i != j && v[j] < v[i])
                    g[i].push_back(j);
        }

        for(int i = 1; i <= n; i++) {
            cout << i << ':';
            for(int j = 0; j < g[i].size(); j++)
                cout << g[i][j] << ' ';
            cout << '\n';
        }

        res = 0;
        for(int i = 1; i <= n; i++) {
            memset(visited, false, sizeof visited);
            res = max(res, lungime(i));
        }

        fout << res << '\n';
    }
}

int main() {
    fin >> n >> t;
    solve();
}