Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
100241 modongtao 四色地图 C++ 解答错误 0 0 MS 248 KB 727 2023-08-25 10:02:24

Tests(0/10):


#include <bits/stdc++.h> using namespace std; bool ar[30][30]; int color[30]; int dfs(int n, int t) { if (color[n] != 0) return color[n]; color[n] = -1; bool *a = new bool[5]; for (int i = 1; i <= t; i++) { if (ar[n][i] && color[i] != -1) { a[color[i]] = true; } } for (int i = 1; i <= 4; i++) { if (!a[i]) { color[n] = i; break; } } delete a; for (int i = 1; i <= t; i++) { if (ar[n][i]) dfs(i, t); } return color[n]; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x, a, b; cin >> x >> a >> b; ar[x][a] = true; ar[x][b] = true; } dfs(1, n); for (int i = 1; i <= n; i++) { cout << color[i] << " "; } return 0; }


测评信息: