This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)3100 + 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) 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] = n+1; seen[u] = 1;
DFSsz(u);
pii cur = {INF, flag+1};
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;
if (cur.F == INF) flag++;
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;
}
Compilation message (stderr)
izlet.cpp: In function 'int32_t main()':
izlet.cpp:100:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
100 | for (int i=1; i<=n; i++) cout << col[i] << " "; cout << endl;
| ^~~
izlet.cpp:100:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
100 | for (int i=1; i<=n; i++) cout << col[i] << " "; cout << endl;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |