Submission #713888

#TimeUsernameProblemLanguageResultExecution timeMemory
713888kaxzertRace (IOI11_race)C++17
0 / 100
8 ms14420 KiB
#include<bits/stdc++.h> using namespace std; #define fto(i, a, b) for(int i = a; i <= b; ++i) #define fdto(i, a, b) for(int i = a; i >= b; --i) #define bugarr(a, i, j) cout << #a << "{" << i << "..." << j << "}:"; fto(k, i, j-1) cout << a[k] << ", "; cout << a[j] << endl; #define ll long long #define db double #define ldb long double #define ff first #define ss second #define pb push_back #define mp make_pair #define eb emplace_back #define vt vector #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define trav(i, a) for(auto &i : a) #define sz(a) (int)a.size() #define pi(a, b) pair<a, b> #define fast ios::sync_with_stdio(false); cin.tie(0) void setIO(string s) { if (sz(s) != 0) { freopen((s+".inp").c_str(),"r",stdin); // freopen((s+".out").c_str(),"w",stdout); } } void setIOusaco(string s) { if (sz(s) != 0) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } template<typename T, typename V> bool ckmin(T &a, V b) {return (b < a)? a = b, true : false;} template<typename T, typename V> bool ckmax(T &a, V b) {return (b > a)? a = b, true : false;} void print(int x) {cout << x;} void print(long long x) {cout << x;} void print(unsigned x) {cout << x;} void print(unsigned long long x) {cout << x;} void print(double x) {cout << fixed << x;} void print(long double x) {cout << fixed << x;} void print(char x) {cout << "'" << x << "'";} void print(string x) {cout << '"' << x << '"';} void print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void print(const pair<T, V> &x) {cout << '{'; print(x.ff); cout << ", "; print(x.ss); cout << '}';} template<typename T> void print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? ", " : ""), print(i); cout << "}";} void _print() {cout << "]" << endl;} template <typename T, typename... V> void _print(T t, V... v) {print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #define bug(x...) cout << "[" << #x << "] = ["; _print(x) const int maxN = 200007; set<pair<int, int> > gr[maxN]; int len[maxN], depth[maxN], n, k; vt<pair<int, int> > ke[maxN]; int ans = (int)1e9; void dfs(int u, int val, int p = -1) { len[u] = val; trav(c, ke[u]) { int v = c.ff; int l = c.ss; if (v == p) continue; depth[v] = depth[u] + 1; dfs(v, val+l, u); } } void dfs2(int u, int p = -1) { trav(c, ke[u]) { int v = c.ff; int l = c.ss; if (v == p) continue; dfs2(v, u); gr[v].insert(mp(len[v], depth[v])); auto it = gr[v].lower_bound(mp(k + len[u], -1)); if (it != gr[v].end() && (it->ff) == k + len[u]) { if (u == 6) {bug(gr[v]);} ans = min(ans, it->ss - depth[u]); } if (sz(gr[u]) < sz(gr[v])) { swap(gr[u], gr[v]); } trav(o, gr[v]) { int need = k - o.ff + len[u]*2; auto it = gr[u].lower_bound(mp(need, -1)); if (it != gr[u].end() && (it->ff) == need) { ans = min(ans, it->ss + o.ss - 2*depth[u]); } } trav(o, gr[v]) gr[u].insert(o); } } int best_path(int n_, int k_, int edges[][2], int weights[]){ //setIO("race_ioi2011"); //ios::sync_with_stdio(false); cin.tie(0); n = n_; k = k_; fto(i, 0, n-2) { int u = edges[i][0]; int v = edges[i][1]; int l = weights[i]; ke[u].pb(mp(v, l)); ke[v].pb(mp(u, l)); } dfs(0, 0); dfs2(0); return (ans == (int)1e9 ? -1 : ans); }

Compilation message (stderr)

race.cpp: In function 'void dfs2(int, int)':
race.cpp:83:7: warning: unused variable 'l' [-Wunused-variable]
   83 |   int l = c.ss;
      |       ^
race.cpp: In function 'void setIO(std::string)':
race.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen((s+".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp: In function 'void setIOusaco(std::string)':
race.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen((s+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen((s+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...