QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730858#1481. Strahler OrderBackToSquare1100 ✓0ms3588kbC++201.3kb2024-11-09 22:02:072024-11-09 22:02:07

Judging History

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

  • [2024-11-09 22:02:07]
  • 评测
  • 测评结果:100
  • 用时:0ms
  • 内存:3588kb
  • [2024-11-09 22:02:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long double ld;

vector<vector<int>> ins(1005);
// vector<vector<int>> outs(1005);
int order[1005];

int get_order(int a) {
    if(order[a] < 1e9) return order[a];
    if(ins[a].size() == 0) {
        order[a] = 1;
        return 1;
    }

    map<int,int> m;
    for(int b : ins[a]) m[get_order(b)]++;

    pair<int,int> c = *(--m.end());
    // cout << "HI " << a << ' ' << c.first << ' ' << c.second << '\n';
    if(c.second == 1) order[a] = c.first;
    else order[a] = c.first + 1;
    return order[a];

}

void solve() {

    int K, N, M;
    cin >> K >> N >> M;
    int A, B;

    for(int i=0;i<M;i++) {
        cin >> A >> B;
        A--;
        B--;

        // outs[A].push_back(B);
        ins[B].push_back(A);
    }

    for(int i=0;i<N;i++) order[i] = 1e9;
    cout << K << ' ' << get_order(N-1) << '\n';
    // for(int i=0;i<N;i++) cout << order[i] << ' ';
    // cout << '\n';


    for(int i=0;i<N;i++) {
        ins[i].clear();
        // outs[i].clear();
        order[i] = 0;
    }


    return;

}


int main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(2);

    int P;
    cin >> P;
    for(int i=0;i<P;i++) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

7
1 7 8
1 3
2 3
6 4
3 4
3 5
6 7
5 7
4 7
2 20 19
1 3
2 3
3 7
4 6
5 6
6 7
8 9
7 9
9 10
11 13
12 13
13 14
15 17
16 17
17 14
14 10
10 19
18 19
19 20
3 10 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
4 10 9
2 3
4 5
8 9
9 10
1 2
6 7
5 6
7 8
3 4
5 13 16
1 12
12 9
9 11
11 13
2 4
4 8
8 12
8 7
9 10
10 11
7 10
4 5
5...

output:

1 3
2 4
3 1
4 1
5 3
6 1
7 1

result:

ok 7 lines