QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#240940 | #7107. Chaleur | ucup-team2307# | AC ✓ | 236ms | 12684kb | C++14 | 3.5kb | 2023-11-05 21:10:22 | 2023-11-05 21:10:22 |
Judging History
answer
#include<bits/stdc++.h>
using ll = long long;
#define all(x) begin(x), end(x)
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
while(T--) {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for(int u, v, i = 0; i < m; i++) {
cin >> u >> v;
// cout << u << " " << v << " " << n << endl;
g[--u].push_back(--v);
g[v].push_back(u);
}
// n = 1e5;
// m = 440 * 439 / 2;
// for(int u = 0; u < n && m; u++) {
// for(int v = 0; v < u && m; v++) {
// g[u].push_back(v);
// g[v].push_back(u);
// m--;
// }
// }
{
vector<int> in_clique(n), deg(n), mark(n);
vector<int> cand(n); iota(all(cand), 0);
for(int i = 0; i < n; i++) deg[i] = g[i].size();
int size = 0;
while(true) {
pair<int, int> v = {-1, -1};
for(auto i : cand) if(!in_clique[i]) {
v = max(v, {deg[i], i});
}
// for(auto i : cand) cout << i << ", "; cout << endl;
if(v.first == -1) break;
// cout << v.second <<"add"<< endl;
size++;
in_clique[v.second] = 1;
for(auto i : g[v.second])
mark[i]++;
vector<int> nc;
for(auto i : cand) {
if((in_clique[i] == 0) & (mark[i] < size)) {//bad vertex
in_clique[i] = -1;
// for(auto &j : g[i])
// deg[j] -= in_clique[j] == 0;//kill vertex
}
if(in_clique[i] == 0) {
nc.push_back(i);
}
}
cand = nc;
}
int ans = 1, anti_ans = 1;
for(int i = 0; i < n; i++) if(in_clique[i] <= 0) {
int d = 0;
for(auto j : g[i]) d += in_clique[j] == 1;
ans += d + 1 == size;
// cout << i << " " << d << endl;
}
cout << ans << " ";
}
{
vector<int> in_clique(n), deg(n), mark(n);
set<pair<int, int>, greater<>> best;
for(int i = 0; i < n; i++) {
deg[i] = n - 1 - g[i].size();
best.insert({deg[i], i});
}
int size = 0;
while(!best.empty()) {
pair<int, int> v = *best.begin();
size++;
in_clique[v.second] = 1;
best.erase(best.begin());
for(auto i : g[v.second]) {
if(in_clique[i] == 0) {
in_clique[i] = -1;
best.erase({deg[i], i});
// for(auto j : g[i]) if(best.count({deg[j], j})) {
// best.erase({deg[j], j});
// deg[j]++;
// best.insert({deg[j], j});
// }
}
}
}
int ans = 1;
for(int i = 0; i < n; i++) if(in_clique[i] <= 0) {
int d = 0;
for(auto j : g[i]) d += in_clique[j] == 1;
ans += d == 1;
}
cout << ans << "\n";
}
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3424kb
input:
3 3 2 1 2 2 3 6 6 1 2 2 3 1 3 1 4 2 5 3 6 4 1 1 2
output:
2 1 1 4 1 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 236ms
memory: 12684kb
input:
2231 1 0 5 7 4 1 3 4 3 1 3 5 4 2 3 2 4 5 5 4 2 1 2 5 2 4 2 3 5 10 3 2 2 5 1 4 4 2 4 5 1 2 1 3 3 5 3 4 1 5 5 10 1 3 2 4 1 4 5 2 2 3 1 5 5 4 1 2 3 4 5 3 5 9 2 5 3 5 2 3 2 1 4 3 3 1 4 1 4 5 2 4 5 4 4 2 4 1 4 5 4 3 5 9 4 1 4 5 3 4 2 4 2 1 3 1 2 5 3 5 3 2 5 4 2 5 2 3 2 1 2 4 5 9 5 2 1 3 4 3 1 2 5 4 4 2 5...
output:
1 1 3 1 4 1 1 5 1 5 2 1 4 1 2 1 4 1 2 1 2 1 3 1 4 1 4 1 1 5 2 1 4 1 1 5 1 5 1 5 3 1 4 1 4 1 4 1 3 1 3 1 4 1 4 1 2 1 4 1 4 1 1 5 1 5 2 1 4 1 4 1 4 1 3 1 2 1 4 1 2 1 4 1 4 1 4 1 3 1 1 5 4 1 4 1 1 5 2 1 4 1 2 1 2 1 1 5 4 1 1 5 3 1 4 1 1 5 2 1 1 5 3 1 3 1 1 5 3 1 3 1 2 1 1 5 4 1 3 1 1 5 2 1 3 1 2 1 2 1 ...
result:
ok 2231 lines
Extra Test:
score: 0
Extra Test Passed