답안 #1089571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089571 2024-09-16T17:00:14 Z ShaShi Izlet (COI19_izlet) C++17
0 / 100
2000 ms 499792 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)3000 + 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] || !chosen[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]+1 == col_dis[i]) cur = {dis[i], col[i]};
        }
 
        col[u] = cur.S;

        if (col[u] > 2) while (1) cout << "SHIT\n";
 
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2045 ms 499792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -