QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#158168 | #7107. Chaleur | ucup-team228# | AC ✓ | 120ms | 19992kb | C++17 | 5.5kb | 2023-09-02 16:16:56 | 2023-09-02 16:16:57 |
Judging History
answer
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
bool first = true; string res = "{";
for (const auto& i : a) {
if (!first) res += ", ";
first = false;
res += to_string(i);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
cerr << " " << to_string(a);
debug_out(b...);
}
#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif
clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }
void Solve();
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
start_timer();
Solve();
#ifdef LOCAL
cerr << fixed << setprecision(3);
cerr << endl << "Time spent: " << get_time() << endl;
#endif
return 0;
}
// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush
// don't waste time on standings
// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT
const int N = 1e5 + 5;
vector<int> g[N];
int deg[N];
int cnt[N];
int pref[N];
int same[N];
vector<int> vs[N];
void init(int n) {
for (int i = 0; i <= n; i++) {
g[i].clear();
deg[i] = 0;
cnt[i] = 0;
pref[i] = 0;
same[i] = 0;
vs[i].clear();
}
}
void Solve() {
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
init(n);
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
int mn = n;
int mx = 0;
for (int i = 1; i <= n; i++) {
deg[i] = (int) g[i].size();
vs[deg[i]].push_back(i);
cnt[deg[i]]++;
mn = min(mn, deg[i]);
mx = max(mx, deg[i]);
}
for (int i = 1; i <= n; i++) {
for (int j : g[i]) {
if (deg[j] > deg[i]) {
pref[i]++;
}
if (deg[j] == deg[i]) {
same[i]++;
}
}
}
if (mx == 0) {
cout << n << " 1\n";
continue;
}
if (mn == n - 1) {
cout << "1 " << n << "\n";
continue;
}
int ptr = mx + 1;
int pref_cnt = 0;
while (1) {
int x = ptr - 1;
if (cnt[x] == 0) {
ptr--;
continue;
}
bool ok = 1;
for (int v : vs[x]) {
if (pref[v] < pref_cnt) {
ok = 0;
break;
}
if (same[v] != cnt[x] - 1) {
ok = 0;
break;
}
}
if (!ok) {
break;
}
pref_cnt += cnt[x];
ptr--;
}
int x = ptr - 1;
bool is_e = 0;
for (int v : vs[x]) {
if (same[v] > 0) {
is_e = 1;
break;
}
}
int t = pref_cnt;
if (!is_e) {
int ans1 = 0;
int ans2 = 0;
int all = 0;
int all_exc_1 = 0;
for (int v : vs[x]) {
if (pref[v] == t) {
all++;
}
else if (pref[v] == t - 1) {
all_exc_1++;
}
}
if (all > 0) {
ans1 = all;
ans2 = 1;
}
else {
ans1 = 1 + all_exc_1;
int k = t;
if (k - 1 > x && cnt[k - 1] > 0) {
ans2 = cnt[k - 1];
}
else { // k - 1 == x
ans2 = 1;
if (k <= mx) {
ans2 += cnt[k];
}
}
}
cout << ans1 << " " << ans2 << "\n";
continue;
}
int k = x + 1;
int ans1 = 1 + cnt[k - 1] - (k - t);
int ans2 = 0;
if (k - t > 0) {
ans2 = k - t;
}
else {
ans2 = 1;
if (k <= mx) {
ans2 += cnt[k];
}
}
cout << ans1 << " " << ans2 << "\n";
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9964kb
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: 120ms
memory: 19992kb
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