QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307291 | #7107. Chaleur | Minhho | RE | 0ms | 6716kb | C++17 | 2.0kb | 2024-01-18 12:46:16 | 2024-01-18 12:46:16 |
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; 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) assert(i <= n), 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;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6716kb
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: -100
Runtime Error
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 ...