답안 #909270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909270 2024-01-17T06:42:10 Z lighton Magic Tree (CEOI19_magictree) C++17
100 / 100
185 ms 54492 KB
#include<bits/stdc++.h>
#define forf(i,a,b) for(int i = a; i<=b; i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
int N,M,K;
int inf = 1e9;
struct ST{
    int t; ll v; int id;
    bool operator<(const ST &r) const{
        if(t==r.t) return id<r.id;
        return t<r.t;
    }
};
vector<int> adj[200001];
ST upd[200001];
void merg (set<ST> &a, set<ST> b){
    for(ST i : b) a.insert(i);
}
void add (set<ST> &now, ST a){
    ST tmp = a; tmp.id = inf;
    now.insert(a);
    auto it = now.upper_bound(tmp);
    ll sum = 0; int flag = 0;
    ST nxt;
    while(it != now.end() && sum <= a.v){
        sum += it->v;
        if(sum > a.v){
            nxt = *it;
            flag = 1;
        }
        it = now.erase(it);
    }
    if(flag){
        nxt.v = sum-a.v;
        now.insert(nxt);
    }
}

struct DSU{
    int grp[200001];
    set<ST> s[200001];
    void init(){
        forf(i,1,N) grp[i] =i ;
    }
    int fi(int x){
        if(grp[x] == x) return x;
        return grp[x] = fi(grp[x]);
    }
    void un(int x, int y){
        x = fi(x); y = fi(y);
        if(s[x].size() > s[y].size()) swap(x,y);
        merg(s[y],s[x]);
        grp[x] = y;
    }
} dsu;


void dfs(int now ,int p = -1){
    for(int &i : adj[now]){
        if(i==p) continue;
        dfs(i,now);
        dsu.un(now,i);
    }
    if(upd[now].id) add(dsu.s[dsu.fi(now)],upd[now]);
}

int main(){
    scanf("%d %d %d" , &N,&M,&K);
    forf(i,2,N){
        int t; scanf("%d" , &t);
        adj[i].push_back(t);
        adj[t].push_back(i);
    }
    forf(i,1,M){
        int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v);
        upd[u] = {t,v,i};
    }
    dsu.init();
    dfs(1);
    ll ans = 0;
    for(ST i : dsu.s[dsu.fi(1)]) ans += i.v;
    printf("%lld" , ans);
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d %d %d" , &N,&M,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:71:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         int t; scanf("%d" , &t);
      |                ~~~~~^~~~~~~~~~~
magictree.cpp:76:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15704 KB Output is correct
2 Correct 5 ms 15708 KB Output is correct
3 Correct 6 ms 15708 KB Output is correct
4 Correct 4 ms 15732 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15708 KB Output is correct
7 Correct 5 ms 15964 KB Output is correct
8 Correct 4 ms 15704 KB Output is correct
9 Correct 5 ms 15708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 32628 KB Output is correct
2 Correct 60 ms 36476 KB Output is correct
3 Correct 185 ms 53820 KB Output is correct
4 Correct 92 ms 36808 KB Output is correct
5 Correct 137 ms 39244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15960 KB Output is correct
2 Correct 6 ms 15960 KB Output is correct
3 Correct 6 ms 15960 KB Output is correct
4 Correct 76 ms 47120 KB Output is correct
5 Correct 85 ms 53076 KB Output is correct
6 Correct 82 ms 46984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 50832 KB Output is correct
2 Correct 173 ms 54492 KB Output is correct
3 Correct 103 ms 41752 KB Output is correct
4 Correct 90 ms 36300 KB Output is correct
5 Correct 80 ms 50000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15704 KB Output is correct
2 Correct 5 ms 15708 KB Output is correct
3 Correct 6 ms 15708 KB Output is correct
4 Correct 4 ms 15732 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15708 KB Output is correct
7 Correct 5 ms 15964 KB Output is correct
8 Correct 4 ms 15704 KB Output is correct
9 Correct 5 ms 15708 KB Output is correct
10 Correct 149 ms 45180 KB Output is correct
11 Correct 149 ms 45908 KB Output is correct
12 Correct 98 ms 36980 KB Output is correct
13 Correct 114 ms 35788 KB Output is correct
14 Correct 83 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 18520 KB Output is correct
2 Correct 40 ms 23380 KB Output is correct
3 Correct 43 ms 23380 KB Output is correct
4 Correct 48 ms 23464 KB Output is correct
5 Correct 22 ms 23508 KB Output is correct
6 Correct 51 ms 27732 KB Output is correct
7 Correct 43 ms 31828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15704 KB Output is correct
2 Correct 5 ms 15708 KB Output is correct
3 Correct 6 ms 15708 KB Output is correct
4 Correct 4 ms 15732 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15708 KB Output is correct
7 Correct 5 ms 15964 KB Output is correct
8 Correct 4 ms 15704 KB Output is correct
9 Correct 5 ms 15708 KB Output is correct
10 Correct 5 ms 15960 KB Output is correct
11 Correct 6 ms 15960 KB Output is correct
12 Correct 6 ms 15960 KB Output is correct
13 Correct 76 ms 47120 KB Output is correct
14 Correct 85 ms 53076 KB Output is correct
15 Correct 82 ms 46984 KB Output is correct
16 Correct 149 ms 45180 KB Output is correct
17 Correct 149 ms 45908 KB Output is correct
18 Correct 98 ms 36980 KB Output is correct
19 Correct 114 ms 35788 KB Output is correct
20 Correct 83 ms 47188 KB Output is correct
21 Correct 25 ms 22356 KB Output is correct
22 Correct 98 ms 35920 KB Output is correct
23 Correct 100 ms 35724 KB Output is correct
24 Correct 154 ms 45652 KB Output is correct
25 Correct 122 ms 36008 KB Output is correct
26 Correct 115 ms 39280 KB Output is correct
27 Correct 99 ms 37012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 15704 KB Output is correct
2 Correct 5 ms 15708 KB Output is correct
3 Correct 6 ms 15708 KB Output is correct
4 Correct 4 ms 15732 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15708 KB Output is correct
7 Correct 5 ms 15964 KB Output is correct
8 Correct 4 ms 15704 KB Output is correct
9 Correct 5 ms 15708 KB Output is correct
10 Correct 72 ms 32628 KB Output is correct
11 Correct 60 ms 36476 KB Output is correct
12 Correct 185 ms 53820 KB Output is correct
13 Correct 92 ms 36808 KB Output is correct
14 Correct 137 ms 39244 KB Output is correct
15 Correct 5 ms 15960 KB Output is correct
16 Correct 6 ms 15960 KB Output is correct
17 Correct 6 ms 15960 KB Output is correct
18 Correct 76 ms 47120 KB Output is correct
19 Correct 85 ms 53076 KB Output is correct
20 Correct 82 ms 46984 KB Output is correct
21 Correct 168 ms 50832 KB Output is correct
22 Correct 173 ms 54492 KB Output is correct
23 Correct 103 ms 41752 KB Output is correct
24 Correct 90 ms 36300 KB Output is correct
25 Correct 80 ms 50000 KB Output is correct
26 Correct 149 ms 45180 KB Output is correct
27 Correct 149 ms 45908 KB Output is correct
28 Correct 98 ms 36980 KB Output is correct
29 Correct 114 ms 35788 KB Output is correct
30 Correct 83 ms 47188 KB Output is correct
31 Correct 10 ms 18520 KB Output is correct
32 Correct 40 ms 23380 KB Output is correct
33 Correct 43 ms 23380 KB Output is correct
34 Correct 48 ms 23464 KB Output is correct
35 Correct 22 ms 23508 KB Output is correct
36 Correct 51 ms 27732 KB Output is correct
37 Correct 43 ms 31828 KB Output is correct
38 Correct 25 ms 22356 KB Output is correct
39 Correct 98 ms 35920 KB Output is correct
40 Correct 100 ms 35724 KB Output is correct
41 Correct 154 ms 45652 KB Output is correct
42 Correct 122 ms 36008 KB Output is correct
43 Correct 115 ms 39280 KB Output is correct
44 Correct 99 ms 37012 KB Output is correct
45 Correct 30 ms 22748 KB Output is correct
46 Correct 105 ms 37480 KB Output is correct
47 Correct 111 ms 37344 KB Output is correct
48 Correct 171 ms 48380 KB Output is correct
49 Correct 132 ms 36768 KB Output is correct
50 Correct 121 ms 40500 KB Output is correct
51 Correct 119 ms 38048 KB Output is correct