Submission #617108

#TimeUsernameProblemLanguageResultExecution timeMemory
617108thezomb1eMousetrap (CEOI17_mousetrap)C++17
0 / 100
313 ms80280 KiB
//thatsramen #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define eb emplace_back #define pb push_back #define ft first #define sd second #define pi pair<int, int> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define dbg(...) dbg_out(__VA_ARGS__) using ll = long long; using ld = long double; using namespace std; using namespace __gnu_pbds; //Constants const ll INF = 5 * 1e18; const int IINF = 2 * 1e9; // const ll MOD = 1e9 + 7; const ll MOD = 998244353; const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ld PI = 3.14159265359; //Templates template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';} void dbg_out() {cerr << endl;} template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); } template<typename T> void mins(T& x, T y) {x = min(x, y);} template<typename T> void maxs(T& x, T y) {x = max(x, y);} template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; //order_of_key(k): number of elements strictly less than k //find_by_order(k): k-th element in the set void setPrec() {cout << fixed << setprecision(15);} void unsyncIO() {cin.tie(0)->sync_with_stdio(0);} void setIn(string s) {freopen(s.c_str(), "r", stdin);} void setOut(string s) {freopen(s.c_str(), "w", stdout);} void setIO(string s = "") { unsyncIO(); setPrec(); if(s.size()) setIn(s + ".in"), setOut(s + ".out"); } // #define TEST_CASES void solve() { int n, t, m; cin >> n >> t >> m; vector<vector<pi>> e(n + 5); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; e[u].pb({v, i}); e[v].pb({u, i}); } vector<bool> mark(n + 5, false); vector<int> path; function<bool(int, int)> dfs_path = [&](int f, int p) -> bool { if (f == t) { return true; } for (const auto &[to, id] : e[f]) { if (to == p) continue; if (dfs_path(to, f)) { path.pb(f); mark[id] = true; return true; } } }; dfs_path(m, -1); vector<int> dp(n + 5, 0); function<void(int, int)> dfs = [&](int f, int p) { vector<pair<int, bool>> al; for (const auto &[to, id] : e[f]) { if (to == p) continue; dfs(to, f); al.pb({dp[to], mark[id]}); } sort(rall(al)); int sz = al.size(); if (sz > 1) { dp[f] = al[1].ft + !al[1].sd + sz - 1; } else if (sz == 1) { dp[f] = !al[0].sd; } }; dfs(m, -1); cout << dp[m]; } int main() { setIO(); int tt = 1; #ifdef TEST_CASES cin >> tt; #endif while (tt--) solve(); return 0; }

Compilation message (stderr)

mousetrap.cpp: In function 'void setIn(std::string)':
mousetrap.cpp:44:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'void setOut(std::string)':
mousetrap.cpp:45:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp: In lambda function:
mousetrap.cpp:73:5: warning: control reaches end of non-void function [-Wreturn-type]
   73 |     };
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...