QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#786254 | #9733. Heavy-light Decomposition | ZhZlzc | WA | 0ms | 3788kb | C++20 | 1.0kb | 2024-11-26 20:53:54 | 2024-11-26 20:53:54 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 1e5 + 10, M = 5010, mod = 1e9 + 7;
const int inf = 1e18;
void solve(){
int n, k;
cin >> n >> k;
vector <PII> a(k + 1);
vector <int> fa(n + 1);
for(int i = 1; i <= k; i++){
cin >> a[i].x >> a[i].y;
for(int j = a[i].x + 1; j <= a[i].y; j++){
fa[j] = j - 1;
}
}
sort(a.begin() + 1, a.end(), [&](PII a, PII b){
return (a.y - a.x) > (b.y - b.x);
});
if(k == 1){
fa[a[1].x] = 0;
for(int i = 1; i <= n; i++) cout << fa[i] << " \n"[ i == n ];
return;
}
if(a[1].y - a[1].x == a[2].y - a[2].x) cout << "IMPOSSIBLE\n";
else{
fa[a[1].x] = 0;
for(int i = 2; i <= n; i++){
fa[a[i].x] = a[1].x;
}
for(int i = 1; i <= n; i++){
cout << fa[i] << " \n"[ i == n ];
}
}
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T = 1;
cin >> T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3788kb
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:
1 1 1 3 4 1 1 7 1 9 10 1 2 0 2 2 IMPOSSIBLE
result:
wrong answer self-loops found. (test case 1)