# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
766189 | 2023-06-25T11:20:18 Z | birthdaycake | Grapevine (NOI22_grapevine) | C++14 | 3000 ms | 12024 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<pair<int,int>>adj[200001]; int grape[200001], ans = 1e18; int vs[200001]; void dfs(int x){ if(grape[x]) ans = min(ans, vs[x]); for(auto s: adj[x]){ if(!vs[s.first]){ vs[s.first] = vs[x] + s.second; dfs(s.first); } } } signed main(){ int n,q; cin >> n >> q; for(int i = 0; i < n - 1; i++){ int a,b,c; cin >> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } for(int i = 0; i < q; i++){ int t; cin >> t; if(t == 1){ int s; cin >> s; vs[s] = 1; dfs(s); if(ans == 1e18) ans = 0; cout << ans - 1 << endl; ans = 1e18; for(int j = 1; j <= n; j++) vs[j] = 0; }else if(t == 2){ int v; cin >> v; grape[v] = !grape[v]; }else{ int a,b,c; cin >> a >> b >> c; for(int j = 0; j < adj[a].size(); j++){ if(adj[a][j].first == b) adj[a][j].second = c; } for(int j = 0; j < adj[b].size(); j++){ if(adj[b][j].first == a) adj[b][j].second = c; } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 5076 KB | Output is correct |
2 | Correct | 16 ms | 5152 KB | Output is correct |
3 | Correct | 17 ms | 5156 KB | Output is correct |
4 | Correct | 15 ms | 5076 KB | Output is correct |
5 | Correct | 17 ms | 5172 KB | Output is correct |
6 | Correct | 16 ms | 5196 KB | Output is correct |
7 | Correct | 13 ms | 5144 KB | Output is correct |
8 | Correct | 12 ms | 5076 KB | Output is correct |
9 | Correct | 12 ms | 5148 KB | Output is correct |
10 | Correct | 15 ms | 5188 KB | Output is correct |
11 | Correct | 15 ms | 5204 KB | Output is correct |
12 | Correct | 14 ms | 5228 KB | Output is correct |
13 | Correct | 12 ms | 5076 KB | Output is correct |
14 | Correct | 11 ms | 5076 KB | Output is correct |
15 | Correct | 13 ms | 5140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3063 ms | 11712 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3065 ms | 11996 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3052 ms | 12024 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3063 ms | 11352 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 5076 KB | Output is correct |
2 | Correct | 16 ms | 5152 KB | Output is correct |
3 | Correct | 17 ms | 5156 KB | Output is correct |
4 | Correct | 15 ms | 5076 KB | Output is correct |
5 | Correct | 17 ms | 5172 KB | Output is correct |
6 | Correct | 16 ms | 5196 KB | Output is correct |
7 | Correct | 13 ms | 5144 KB | Output is correct |
8 | Correct | 12 ms | 5076 KB | Output is correct |
9 | Correct | 12 ms | 5148 KB | Output is correct |
10 | Correct | 15 ms | 5188 KB | Output is correct |
11 | Correct | 15 ms | 5204 KB | Output is correct |
12 | Correct | 14 ms | 5228 KB | Output is correct |
13 | Correct | 12 ms | 5076 KB | Output is correct |
14 | Correct | 11 ms | 5076 KB | Output is correct |
15 | Correct | 13 ms | 5140 KB | Output is correct |
16 | Execution timed out | 3063 ms | 11712 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |