QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#636053 | #9453. Graph Generator | ucup-team1264# | AC ✓ | 462ms | 12464kb | C++20 | 2.7kb | 2024-10-12 22:00:50 | 2024-10-12 22:00:56 |
Judging History
answer
// https://www.youtube.com/watch?v=CrymicX875M
// Angel of mercy
// How did you move me
// Why am I on my feet again
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
void solve() {
int n, m; cin >> n >> m;
bool feas = true;
vector<vector<int>> adj(n);
vector<int> deg(n);
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
deg[u]++; deg[v]++;
}
auto oadj = adj;
priority_queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
q.emplace(deg[i], i);
}
vector<int> vis(n);
vector<int> ans;
while (!q.empty()) {
auto [sz, u] = q.top(); q.pop();
if (sz != deg[u]) continue;
vis[u] = 1; ans.push_back(u);
for (int v: adj[u]) vis[v] = 1;
for (int v: adj[u]) {
vector<int> nadj;
for (int w: adj[v]) {
if (!vis[w]) {
cout << "No\n";
return;
}
if (w != u) nadj.push_back(w);
}
adj[v].swap(nadj);
}
for (int v: adj[u]) {
deg[v]--;
vis[v] = 0;
q.emplace(deg[v], v);
}
deg[u] = 0;
adj[u].clear();
}
class UnionFindSet {
vector<int> fa, sz;
public:
UnionFindSet(int n) : fa(n), sz(n, 1) {
for (int i = 0; i < n; i++) {
fa[i] = i;
}
}
int size(int x) { return sz[find(x)]; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) return 0;
if (sz[x] < sz[y]) swap(x, y);
fa[y] = x, sz[x] += sz[y];
return 1;
}
};
cout << "Yes\n";
vis.assign(n, 0);
reverse(ans.begin(), ans.end());
UnionFindSet ufs(n);
for (int x: ans) {
cout << x + 1 << " ";
vector<int> tmp;
for (int y: oadj[x]) {
if (!vis[y]) continue;
if (ufs.find(y) != ufs.find(x)) {
ufs.merge(x, y);
tmp.push_back(y);
}
}
cout << tmp.size() << " ";
for (int y: tmp) cout << y + 1 << " ";
cout << "\n";
vis[x] = 1;
}
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
};
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 3 0 4 4 1 2 2 3 3 4 2 4 5 5 1 2 2 3 3 4 4 5 2 4
output:
Yes 1 0 2 0 3 0 Yes 1 0 3 0 4 1 3 2 2 1 3 No
result:
ok 3 cases passed
Test #2:
score: 0
Accepted
time: 462ms
memory: 12464kb
input:
4176 10 15 1 4 9 1 3 7 8 1 2 1 5 4 5 1 10 1 7 1 10 7 10 3 6 4 3 1 6 1 9 2 7 10 6 7 1 7 1 4 7 2 4 2 5 2 3 1 1 6 2 6 5 1 6 8 5 2 3 1 4 6 2 1 5 1 1 4 6 2 6 1 9 15 5 1 4 2 7 1 1 8 2 3 5 8 1 9 4 3 6 5 9 2 3 1 4 1 7 2 9 7 1 6 6 11 1 2 3 5 3 1 3 2 4 3 1 6 4 2 1 4 5 4 5 1 5 2 6 6 1 6 6 3 1 3 1 5 4 2 2 1 10 ...
output:
Yes 2 0 3 0 5 0 6 0 8 0 7 1 3 9 1 2 4 2 5 6 10 1 7 1 4 4 9 8 10 No No No Yes 2 0 6 0 3 1 2 4 1 3 5 1 3 1 2 2 6 No No Yes 2 0 3 0 4 0 5 1 4 7 1 3 6 1 4 1 3 4 2 7 Yes 4 0 5 0 6 0 7 0 8 0 9 0 10 0 3 2 6 10 2 5 5 10 7 9 8 1 2 8 4 Yes 4 0 6 0 7 0 8 0 9 0 5 2 7 8 2 2...
result:
ok 4176 cases passed
Extra Test:
score: 0
Extra Test Passed