QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751243#9733. Heavy-light Decompositionhhdhh#WA 0ms3612kbC++231.2kb2024-11-15 17:41:502024-11-15 17:41:51

Judging History

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

  • [2024-11-15 17:41:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-15 17:41:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
typedef pair<ll, ll> pll;
const ll N = 3e5 + 10;

void solve()
{
    ll n, m;
    cin >> n >> m;
    ll fa[n + 5];
    vector<pll>ve;
    rep(i, 1, n) {
        fa[i] = 0;
    }
    rep(i, 1, m) {
        ll l, r;
        cin >> l >> r;
        ve.push_back({-1 * (r - l + 1), l});
        per(j, r, l + 1) {
            fa[j] = j - 1;
        }
    }
    if(n == 1) {
        cout << 0 << endl;
    }
    else {
        sort(all(ve));
        if(ve[0].first == ve[1].first) {
            cout << "IMPOSSIBLE" << endl;
        }
        else {
            rep(i, 1, sz(ve) - 1) {
                fa[ve[i].second] = ve[i - 1].second;
            }
            rep(i, 1, n) {
                cout << fa[i] << " \n"[i == n];
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    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: 0ms
memory: 3612kb

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 7 9 7 1 9 10 6
2 0 2 1
IMPOSSIBLE

result:

wrong answer vertex 6 is not a leaf (test case 1)