Submission #1088058

# Submission time Handle Problem Language Result Execution time Memory
1088058 2024-09-13T19:09:43 Z ShaShi Izlet (COI19_izlet) C++17
0 / 100
367 ms 45328 KB
#include <bits/stdc++.h>
 
// #define int long long
 
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
 
#define F first 
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define endl "\n"
 
 
 
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
 
const int MAXN = (int)3010 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;


int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, flag2;
int A[MAXN][MAXN], dis[MAXN], col[MAXN], cnt[MAXN], col_dis[MAXN];
bool seen[MAXN], chosen[MAXN];
vector<int> adj[MAXN];
vector<pii> edge;


inline void add(int x) {
    if (!cnt[x]) flag2++;
    cnt[x]++;
}

inline void rem(int x) {
    cnt[x]--;
    if (!cnt[x]) flag2--;
}


void DFSsz(int v, int p=-1) {
    add(col[v]); col_dis[v] = flag2;

    for (int u:adj[v]) {
        if (u == p || !seen[u]) continue;

        dis[u] = dis[v]+1;
        DFSsz(u, v);
    }

    rem(col[v]);
}



int32_t main() {
    #ifdef LOCAL
    // freopen("inp.in", "r", stdin);
    // freopen("res.out", "w", stdout);
    #else
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> tmp >> n;

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

    queue<int> Q; Q.push(1); chosen[1] = 1;

    while (Q.size()) {
        u = Q.front(); Q.pop();

        dis[u] = 0; col[u] = u; seen[u] = 1;

        DFSsz(u);

        pii cur = {INF, u};

        for (int i=1; i<=n; i++) {
            if (!seen[i] || i == u) continue;
            if (dis[i] < cur.F && A[u][i] != col_dis[i]) cur = {dis[i], col[i]};
        }

        col[u] = cur.S;

        for (int i=1; i<=n; i++) {
            if (chosen[i] || i == u || A[u][i] > 2) continue;
            chosen[i] = 1; edge.pb({u, i}); Q.push(i); adj[u].pb(i); adj[i].pb(u);
        }
    }

    for (int i=1; i<=n; i++) {cout << col[i] << " ";} cout << endl;
    for (auto cur:edge) {cout << cur.F << " " << cur.S << endl;}

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 367 ms 45328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -