Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
38940 Gapple 【S】T3 C++ 通过 100 300 MS 46724 KB 1347 2025-11-19 19:57:42

Tests(50/50):


#include <iostream> #include <random> #include <unordered_set> #include <vector> using namespace std; using i64 = long long; minstd_rand0 rng(110108200911120917); inline int randint(int l, int r) { return l + rng() % (r - l + 1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<vector<int>> graph(n + 1); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } for (;;) { int u = randint(1, n - 1), v = randint(u + 1, n); unordered_set<int> leaf_u(graph[u].begin(), graph[u].end()), leaf_v(graph[v].begin(), graph[v].end()), leaves = leaf_u; leaves.insert(leaf_v.begin(), leaf_v.end()); if (leaves.size() == graph[u].size() + graph[v].size() || (leaves.size() + 1 == graph[u].size() + graph[v].size() && 0 == leaf_u.count(v) && 0 == leaf_v.count(u))) { for (int i = 1; i <= n; ++i) { if (i == u) cout << "1 "; else if (i == v) cout << "2 "; else cout << "3 "; } cout << '\n'; break; } } return 0; }


测评信息: