QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209703 | #7107. Chaleur | zqs | AC ✓ | 62ms | 20308kb | C++14 | 2.7kb | 2023-10-10 16:42:48 | 2023-10-10 16:42:48 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
#include <cassert>
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++)
char buf[100000], *p1, *p2;
inline int read() {
char ch; int x = 0; while ((ch = gc) < 48); do x = x * 10 + ch - 48; while ((ch = gc) >= 48); return x;
}
int deg[100005], a[100005], bel[100005], seq[100005], n, m;
bool vis[100005];
std::vector<int> G[100005], vec[100005];
int adjust1() {
int cnt = 0;
for (int i = 1; i <= n; ++ i) if (bel[i]) ++ cnt;
for (int i = 1; i <= n; ++ i) if (!bel[i]) {
int x = 0;
for (int j : G[i]) if (bel[j]) ++ x;
if (x == cnt) return i;
}
return 0;
}
int adjust2() {
for (int i = 1; i <= n; ++ i) if (bel[i]) {
bool flag = true;
for (int j : G[i]) if (!bel[j]) {flag = false; break;}
if (flag) return i;
}
return 0;
}
int calc1() {
memset(vis, false, sizeof vis);
int cnt = 0, ans = 1;
for (int i = 1; i <= n; ++ i) if (bel[i]) seq[++ cnt] = i;
for (int i = 1; i <= n; ++ i) if (!bel[i] && deg[i] >= cnt - 1) {
int tot = 0;
for (int j : G[i]) vis[j] = true, tot += bel[j];
if (tot == cnt - 1) ++ ans;
for (int j : G[i]) vis[j] = false;
}
return ans;
}
int calc2() {
memset(vis, false, sizeof vis);
int cnt = 0, ans = 1;
for (int i = 1; i <= n; ++ i) if (bel[i]) ++ cnt;
for (int i = 1; i <= n; ++ i) if (bel[i] && deg[i] == cnt) ++ ans;
return ans;
}
bool check() {
for (int u = 1; u <= n; ++ u)
for (int v : G[u]) assert(bel[u] || bel[v]);
int cnt = 0;
for (int i = 1; i <= n; ++ i) if (bel[i]) seq[++ cnt] = i;
for (int u = 1; u <= cnt; ++ u) {
int jb=0;
for (int v : G[seq[u]]) jb += bel[v];
assert(jb == cnt - 1);
}
return true;
}
int main() {
int _ = read();
while (_ --) {
memset(deg, 0, sizeof deg);
n = read(), m = read();
for (int i = 0; i <= n; ++ i) vec[i].clear(), G[i].clear(), deg[i] = bel[i] = 0;
for (int i = 1, u, v; i <= m; ++ i) {
u = read(), v = read();
if (u > v) u ^= v ^= u ^= v;
G[u].emplace_back(v), G[v].emplace_back(u), ++ deg[u], ++ deg[v];
}
if (!m) {printf("%d 1\n", n); continue;}
if (m == 1ll * n * (n - 1) >> 1) {printf("1 %d\n", n); continue;}
for (int i = 1; i <= n; ++ i) vec[deg[i]].emplace_back(i);
for (int i = 0, k = 0; i <= n; ++ i) for (int j : vec[i]) a[++ k] = j;
int l = n - 1;
memset(vis, false, sizeof vis);
for (int i = 1; i <= n; ++ i) {
for (int j : G[a[i]]) if (vis[j]) {l = i - 1; break;}
if (l != n - 1) break;
vis[a[i]] = true;
}
for (int i = l + 1; i <= n; ++ i) bel[a[i]] = 1;
int t = adjust1(); bel[t] = 1, printf("%d ", calc1());
bel[t] = 0; bel[adjust2()] = 0; printf("%d\n", calc2());
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9168kb
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: 62ms
memory: 20308kb
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