Submission #234135

# Submission time Handle Problem Language Result Execution time Memory
234135 2020-05-23T09:33:58 Z Vimmer Izlet (COI19_izlet) C++14
0 / 100
588 ms 53724 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

#define sz(x) ll(x.size())
#define base 1000000
#define M ll(1e9+7)
#define N 3005
#define F first
#define S second
#define pb push_back
#define in insert
#define eb emplace_back
#define ed "\n"

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef short int si;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int rk[N], pr[N], n, a[N][N], clr[N], kol;

vector <int> g[N];

vector <pair <int, int> > vr;

int fnd(int x) {if (pr[x] != x) pr[x] = fnd(pr[x]); return pr[x];}

void link(int x, int y) {if (fnd(x) == fnd(y)) return; g[x].pb(y); g[y].pb(x); x = fnd(x); y = fnd(y); if (rk[x] < rk[y]) swap(x, y); rk[x] += rk[y]; pr[y] = x;}

void dfs(int v, int p)
{
    int color = -1;

    for (auto it : vr) if (it.F == a[it.S][v]) color = clr[it.S];

    if (color == -1) clr[v] = ++kol;

    for (auto it : vr) if (clr[it.S] != clr[v]) it.F++;

    vr.pb({1, v});

    for (auto it : g[v])
    {
        if (it == p) continue;

        dfs(it, v);
    }

    for (auto it : vr) if (clr[it.S] != clr[v]) it.F--;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> n;

    for (int i = 1; i <= n; i++) {rk[i] = 1; pr[i] = i;}

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) cin >> a[i][j];

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          if (a[i][j] == 1) link(i, j);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          if (a[i][j] == 2) link(i, j);

    dfs(1, -1);

    for (int i = 1; i <= n; i++)
      cout << clr[i] << " ";

    cout << '\n';

    for (int i = 1; i <= n; i++)
        for (auto it : g[i])
          if (it > i) cout << i << " " << it << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Integer 0 violates the range [1, 30]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 588 ms 53724 KB Integer 0 violates the range [1, 3000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Integer 0 violates the range [1, 30]
2 Halted 0 ms 0 KB -