Submission #767071

# Submission time Handle Problem Language Result Execution time Memory
767071 2023-06-26T11:04:35 Z birthdaycake Grapevine (NOI22_grapevine) C++17
0 / 100
545 ms 29600 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
#define mod 1000000007
using namespace std;

vector<int>adj[200001];
int g[200001],sub[200001];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,q; cin >> n >> q;
    map<pair<int,int>,int>d;
    for(int i = 0; i < n - 1; i++){
        int a,b,c; cin >> a >> b >> c;
        d[{a,b}] = c;
        d[{b,a}] = c;
    }
    for(int i = 1; i <= 2 * n; i++) sub[i] = INT_MAX;
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int node; cin >> node;
            int ans = INT_MAX, dist = 0;
            while(node > 0){
                if(sub[node] != INT_MAX) ans = min(ans, sub[node] + dist);
                dist += d[{node / 2, node}];
                node /= 2;
            }
            if(ans == INT_MAX) ans = -1;
            cout << ans << endl;
        }else if(t == 2){
            int grape; cin >> grape;
            g[grape] = !g[grape];
            if(g[grape]){
                while(grape > 0){
                    sub[grape] = min(sub[grape * 2] + d[{grape * 2, grape}], sub[grape * 2 + 1] + d[{grape * 2 + 1, grape}]);
                    if(g[grape]) sub[grape] = 0;
                    grape /= 2;
                }
            }else{
                sub[grape] = INT_MAX;
                while(grape > 0){
                    sub[grape] = min(sub[grape * 2] + d[{grape * 2, grape}], sub[grape * 2 + 1] + d[{grape * 2 + 1, grape}]);
                    if(g[grape]) sub[grape] = 0;
                    grape /= 2;
                }
            }
            
        }else{
            int a,b,c; cin >> a >> b >> c;
            d[{a,b}] = c;
            d[{b,a}] = c;
            a = min(a,b);
            while(a > 0){
                sub[a] = min(sub[a * 2] + d[{a * 2, a}], sub[a * 2 + 1] + d[{a * 2 + 1, a}]);
                if(g[a]) sub[a] = 0;
                a /= 2;
            }
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 394 ms 26568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 477 ms 20760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 545 ms 29600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 520 ms 28920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5460 KB Output isn't correct
2 Halted 0 ms 0 KB -