Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
100318 | modongtao | 四色地图 | C++ | 解答错误 | 60 | 0 MS | 256 KB | 1110 | 2023-08-25 11:10:59 |
#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* inp() { string s; getline(cin, s); int *p = new int[105]; int cur=0, cnt=0; for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') { p[++cnt] = cur; cur = 0; } else cur = cur * 10 + (s[i] - '0'); } p[++cnt] = cur; p[++cnt] = -1; return p; } int main() { int n; cin >> n; cin.get(); for (int i = 1; i <= n; i++) { int *p = inp(); int x = p[1]; for (int j = 2;;j++) { if (p[j] == -1) break; ar[x][p[j]] = true; } } for (int i = 1; i <= n; i++) dfs(i, n); for (int i = 1; i <= n; i++) { cout << color[i] << " "; } cout << endl; return 0; }