QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#742710 | #9733. Heavy-light Decomposition | asaltfish | WA | 0ms | 3552kb | C++23 | 1.9kb | 2024-11-13 17:07:59 | 2024-11-13 17:08:00 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<numeric>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define endl "\n"
using namespace std;
int t, n, m, fa[200005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> t;
while (t--)
{
cin >> n >> m;
map<int, vector<pair<int, int>>>mp;
while (m--)
{
ll l, r;
cin >> l >> r;
mp[r - l + 1].emplace_back(l, r);
}
if ((mp.size() == 1&&mp.rbegin()->second.size()>1 )|| (mp.rbegin()->second.size()>1&&mp.rbegin()->first == 2))
{
cout << "IMPOSSIBLE" << endl;
continue;
}
int be = 0, faa = 0;
for (auto p=mp.rbegin();p!=mp.rend();p++)
{
auto [len, vc] = *p;
if (!be)
{
be = 1;
fa[vc[0].first] = 0;
faa = vc[0].first;
for (int i = vc[0].first + 1; i <= vc[0].second; i++)
fa[i] = i - 1;
for (int i = 1; i < vc.size(); i++)
{
auto [l, r] = vc[i];
fa[l] = faa;
while (++l <= r)
fa[l] = l - 1;
}
faa++;
}
else
{
for (int i = 0; i < vc.size(); i++)
{
auto [l, r] = vc[i];
fa[l] = faa;
while (++l <= r)
fa[l] = l - 1;
}
}
}
for (int i = 1; i <= n; i++)
cout << fa[i] << " ";
cout << endl;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
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 2 2 7 2 9 10 2 3 0 2 3 IMPOSSIBLE
result:
wrong answer vertex 3 is not a leaf (test case 2)