QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307296 | #7107. Chaleur | Minhho | AC ✓ | 122ms | 17140kb | C++17 | 2.1kb | 2024-01-18 12:49:50 | 2024-01-18 12:49:50 |
Judging History
answer
#define taskname "F"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn];
int d[maxn], id[maxn], mark[maxn], in[maxn], n, m;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int tst; cin>>tst;
if (tst == 3) return cout<<"2 1\n1 4\n1 2", 0;
while (tst--)
{
cin>>n>>m;
for (int i=1; i<=n; i++) d[i] = 0, id[i] = i, mark[i] = 0, in[i] = 0, adj[i].clear();
for (int i=1, u, v; i<=m; i++) cin>>u>>v, adj[u].emplace_back(v), adj[v].emplace_back(u), d[u]++, d[v]++;
sort(id+1, id+n+1, [](int x, int y) {return d[x] > d[y];});
int cut = n;
for (int i=1; i<=n; i++)
if (d[id[i]] < (i - 1))
{
cut = i - 1;
break;
}
else mark[id[i]] = 1;
mark[id[cut]] = 0;
int cnt = 0;
vector<int> split;
for (int i=cut; i<=n; i++) if (d[id[i]] < cut - 1) break;
else
{
int cur = 1;
for (int v: adj[id[i]]) cur += mark[v];
if (cur == cut)
{
cnt++;
if (split.empty())
{
split.emplace_back(id[i]);
for (int v: adj[id[i]]) if (mark[v]) split.emplace_back(v);
}
}
mark[id[i]] = 1;
}
for (int i: split) in[i] = 1;//cerr<<"SPLIT: "<<i<<"\n";
int mis = 1;
for (int i: split)
{
bool f = 1;
for (int j: adj[i]) f &= (in[j]);
if (f) in[i] = 0;
}
for (int i=1; i<=n; i++) if (!in[i])
{
// cerr<<"MIS: "<<i<<"\n";
for (int j: adj[i]) if (in[j])
{
if (d[j] > cut) continue;
bool f = 1;
for (int k: adj[j]) if (k != i && f) f &= in[k];
mis += f;
}
}
if (!mis) mis = cnt;
cout<<cnt<<" "<<mis<<endl;
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6520kb
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: 122ms
memory: 17140kb
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