QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328840 | #4243. Good Coloring | hos_lyric | WA | 0ms | 3784kb | C++14 | 3.1kb | 2024-02-16 08:39:58 | 2024-02-16 08:39:59 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
int N, M, K;
vector<int> C;
vector<int> A, B;
vector<vector<int>> graph;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d%d", &N, &M, &K);
C.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &C[u]);
--C[u];
}
A.resize(M);
B.resize(M);
for (int i = 0; i < M; ++i) {
scanf("%d%d", &A[i], &B[i]);
--A[i];
--B[i];
}
graph.assign(N, {});
for (int i = 0; i < M; ++i) {
graph[A[i]].push_back(B[i]);
graph[B[i]].push_back(A[i]);
}
vector<vector<int>> uss(K);
for (int u = 0; u < N; ++u) {
uss[C[u]].push_back(u);
}
// cerr<<COLOR("92")<<"uss = "<<uss<<", graph = "<<graph<<COLOR()<<endl;
// new color l > 0 ==> adjacent some of new color (l-1)
vector<int> ds(N, -1);
vector<int> par(N, -1);
for (int k = 0; k < K; ++k) {
for (const int v : uss[k]) {
for (const int u : graph[v]) {
if (chmax(ds[v], ds[u] + 1)) {
par[v] = u;
}
}
}
}
const int L = *max_element(ds.begin(), ds.end()) + 1;
vector<int> path(L, -1);
for (int u = 0; u < N; ++u) if (ds[u] == L - 1) {
path[L - 1] = u;
break;
}
for (int l = L - 1; --l >= 0; ) {
path[l] = par[path[l + 1]];
}
// cerr<<"ds = "<<ds<<endl;
// cerr<<"par = "<<par<<endl;
// cerr<<"path = "<<path<<endl;
for (int l = 0; l < L; ++l) {
assert(ds[path[l]] == l);
}
printf("%d", L);
for (int u = 0; u < N; ++u) {
printf(" %d", ds[u] + 1);
}
puts("");
for (int l = 0; l < L; ++l) {
if (l) printf(" ");
printf("%d", path[l] + 1);
}
puts("");
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3784kb
input:
2 3 3 3 1 2 3 1 2 2 3 3 1 3 1 3 1 2 3 1 2
output:
3 1 2 3 1 2 3 2 1 2 0 1 2
result:
wrong answer Integer 0 violates the range [1, 2] (test case 2)