QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742710#9733. Heavy-light DecompositionasaltfishWA 0ms3552kbC++231.9kb2024-11-13 17:07:592024-11-13 17:08:00

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 17:08:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-11-13 17:07:59]
  • 提交

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)