QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743812 | #9733. Heavy-light Decomposition | ucup-team4975# | WA | 1ms | 3508kb | C++14 | 2.0kb | 2024-11-13 20:05:36 | 2024-11-13 20:05:37 |
Judging History
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
void solve()
{
int n, m;
cin >> n >> m;
vector<PII> a(m + 1);
for (int i = 1; i <= m; i++) {
cin >> a[i].fir >> a[i].sec;
}
if (m == 1) {
for (int i = 0; i < n; i++) {
cout << i << " ";
}
cout << el;
return;
}
sort(next(a.begin()), a.end(),
[&](PII x, PII y) { return x.sec - x.fir > y.sec - y.fir; });
int mx = a[1].sec - a[1].fir + 1;
if (a[2].sec - a[2].fir + 1 != mx) {
int tmp = 1;
int rt = 0;
for (int i = 1; i <= m; i++) {
int now = rt;
for (int j = a[i].fir; j <= a[i].sec; j++) {
cout << now << " ";
now = tmp;
tmp++;
}
rt = 1;
}
cout << el;
return;
}
int flag = 0;
for (int i = 2; i <= m; i++) {
if (a[i].sec - a[i].fir + 1 <= mx - 2) {
flag = i;
break;
}
}
if (!flag) {
cout << "IMPOSSIBLE" << el;
return;
}
int tmp = 1;
int rt = 0;
for (int i = 1; i <= m; i++) {
int now = rt;
if (i == flag)
now = 2;
for (int j = a[i].fir; j <= a[i].sec; j++) {
cout << now << " ";
now = tmp;
tmp++;
}
rt = 1;
}
cout << el;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3508kb
input:
3 12 5 1 5 9 11 7 8 6 6 12 12 4 3 1 1 4 4 2 3 2 2 1 1 2 2
output:
0 1 2 3 4 1 6 7 1 9 1 1 0 1 1 1 IMPOSSIBLE
result:
wrong answer 11's parent should be 10, but 1 found (test case 1)