제출 #1115831

#제출 시각아이디문제언어결과실행 시간메모리
1115831ThanhsRailway (BOI17_railway)C++17
0 / 100
99 ms91836 KiB
#include <bits/stdc++.h> using namespace std; #define name "TENBAI" #define fi first #define se second #define int long long #define endl '\n' #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 2e5 + 5; const int LG = 20; vector<int> ans; vector<pair<int, int>> g[NM]; int n, m, k, tin[NM], tout[NM], dep[NM], timer, dp[NM]; pair<int, int> st[NM][LG], p[NM]; int lca(int u, int v) { u = tin[u], v = tin[v]; if (u > v) swap(u, v); int L = __lg(v - u + 1); return min(st[u][L], st[v - (1 << L) + 1][L]).se; } bool ancestor(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; } void upd(vector<int>& V) { sort(V.begin(), V.end(), [&](const int& x, const int& y){return tin[x] < tin[y];}); for (int j = V.size(), i = 1; i < j; i++) V.push_back(lca(V[i], V[i - 1])); sort(V.begin(), V.end(), [&](const int& x, const int& y){return tin[x] < tin[y];}); V.erase(unique(V.begin(), V.end()), V.end()); sort(V.begin(), V.end(), [&](const int& x, const int& y){return tin[x] < tin[y];}); vector<int> st; for (int u : V) { if (st.size() && !ancestor(st.back(), u)) st.pop_back(); if (st.size()) dp[st.back()]--, dp[u]++; st.push_back(u); } } void dfs(int u) { st[++timer][0] = {dep[u], u}; tin[u] = timer; for (auto v : g[u]) if (v.fi != p[u].fi) { dep[v.fi] = dep[u] + 1; p[v.fi] = {u, v.se}; dfs(v.fi); st[++timer][0] = {dep[u], u}; } tout[u] = timer; } void DFS(int u) { for (auto v : g[u]) if (v.fi != p[u].fi) { DFS(v.fi); dp[u] += dp[v.fi]; } if (u != 1) cout << u << ' ' << p[u].fi << ' ' << dp[u] << endl; if (u != 1 && dp[u] >= k) ans.push_back(p[u].se); } void solve() { cin >> n >> m >> k; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].emplace_back(v, i); g[v].emplace_back(u, i); } dfs(1); for (int i = 1; (1 << i) <= timer; i++) for (int j = 1; j + (1 << i) - 1 <= timer; j++) st[j][i] = min(st[j][i - 1], st[j + (1 << i - 1)][i - 1]); while (m--) { int t; cin >> t; vector<int> V; while (t--) { int u; cin >> u; V.push_back(u); } upd(V); } DFS(1); sort(ans.begin(), ans.end()); cout << ans.size() << endl; for (int t : ans) cout << t << ' '; } signed main() { if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } else if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc = 1; // cin >> tc; while (tc--) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

railway.cpp: In function 'void solve()':
railway.cpp:99:57: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   99 |             st[j][i] = min(st[j][i - 1], st[j + (1 << i - 1)][i - 1]);
      |                                                       ~~^~~
railway.cpp: In function 'int main()':
railway.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
railway.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(name".out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...