Submission #713887

#TimeUsernameProblemLanguageResultExecution timeMemory
713887kaxzertRace (IOI11_race)C++17
Compilation error
0 ms0 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: At global scope:
race.cpp:111:5: error: expected initializer before 'n'
  111 |     n = n_;
      |     ^
race.cpp:112:2: error: 'k' does not name a type
  112 |  k = k_;
      |  ^
race.cpp:5:22: error: expected unqualified-id before 'for'
    5 | #define fto(i, a, b) for(int i = a; i <= b; ++i)
      |                      ^~~
race.cpp:113:2: note: in expansion of macro 'fto'
  113 |  fto(i, 0, n-2) {
      |  ^~~
race.cpp:113:6: error: 'i' does not name a type
  113 |  fto(i, 0, n-2) {
      |      ^
race.cpp:5:37: note: in definition of macro 'fto'
    5 | #define fto(i, a, b) for(int i = a; i <= b; ++i)
      |                                     ^
race.cpp:5:45: error: expected unqualified-id before '++' token
    5 | #define fto(i, a, b) for(int i = a; i <= b; ++i)
      |                                             ^~
race.cpp:113:2: note: in expansion of macro 'fto'
  113 |  fto(i, 0, n-2) {
      |  ^~~
race.cpp:121:5: error: expected constructor, destructor, or type conversion before '(' token
  121 |  dfs(0, 0);
      |     ^
race.cpp:122:6: error: expected constructor, destructor, or type conversion before '(' token
  122 |  dfs2(0);
      |      ^
race.cpp:124:2: error: expected unqualified-id before 'return'
  124 |  return (ans == (int)1e9 ? -1 : ans);
      |  ^~~~~~
race.cpp:125:2: error: expected declaration before '}' token
  125 |  }
      |  ^
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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~