Submission #242280

# Submission time Handle Problem Language Result Execution time Memory
242280 2020-06-27T08:05:37 Z cheeheng Magic Tree (CEOI19_magictree) C++14
14 / 100
70 ms 10104 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> AdjList[100005];

int d[100005];
int w[100005];
int L[100005];

int main(){
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);

    bool subtask3 = true;
    for(int i = 2; i <= n; i ++){
        int p;
        scanf("%d", &p);
        subtask3 &= p == i-1;

        AdjList[p].push_back(i);
    }

    bool subtask2 = true;
    long long ans2 = 0;
    memset(d, -1, sizeof(d));
    for(int i = 1; i <= m; i ++){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        subtask3 &= (z == 1);
        subtask2 &= AdjList[x].empty();
        d[x] = y;
        w[x] = z;
        ans2 += w[x];
    }

    if(subtask2){
        printf("%lld", ans2);
        return 0;
    }

    if(subtask3){
        int lis = 0;
        /*for(int i = n; i >= 2; i --){
            printf("%d ", d[i]);
        }
        printf("\n");*/
        for(int i = n; i >= 2; i --){
            if(d[i] == -1){continue;}
            int pos = upper_bound(L, L+lis, d[i])-L;
            L[pos] = d[i];
            if(pos == lis){
                lis ++;
            }
        }
        printf("%d\n", lis);
        return 0;
    }else{
        throw;
    }

    return 0;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &p);
         ~~~~~^~~~~~~~~~
magictree.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 6016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4856 KB Output is correct
2 Correct 37 ms 5632 KB Output is correct
3 Correct 67 ms 4256 KB Output is correct
4 Correct 57 ms 3960 KB Output is correct
5 Correct 60 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3072 KB Output is correct
2 Correct 7 ms 3120 KB Output is correct
3 Correct 6 ms 3072 KB Output is correct
4 Correct 56 ms 6652 KB Output is correct
5 Correct 60 ms 6904 KB Output is correct
6 Correct 62 ms 6524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 10104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 6016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 6784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 6016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 6016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -