Submission #1125825

#TimeUsernameProblemLanguageResultExecution timeMemory
1125825wibulordRailway (BOI17_railway)C++20
36 / 100
76 ms23232 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb emplace_back #define ii pair<int, int> #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define sz(s) (int)((s).size()) #define all(a) a.begin(), a.end() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define F0R(i, b) for (int i = 0, _b = (b); i < _b; ++i) #define FORd(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define F0Rd(i, b) for (int i = (b)-1; i >= 0; i--) #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; template<typename T1,typename T2> bool ckmax(T1 &x,const T2 &y){if(x<y){x=y; return 1;} return 0;} template<typename T1,typename T2> bool ckmin(T1 &x,const T2 &y){if(y<x){x=y; return 1;} return 0;} const int MOD = (int)1e9 + 7; const int mod = 998244353; const int N = 1e5 + 10, M = 18; const long long INF = (long long)1e18 + 11; /* /\_/\ (= ._.) / >? \>$ */ int n, m, k, tms; int idx[N], id[N], cnt[N]; int num[N], h[N], up[N][M]; vector<ii> adj[N]; vector<int> ans; void dfs(int u, int p = -1){ num[u] = ++tms; for(auto [v, e] : adj[u]) if(v != p){ id[v] = e; h[v] = h[u] + 1, up[v][0] = u; FOR(i, 1, __lg(h[v])) up[v][i] = up[up[v][i-1]][i-1]; dfs(v, u); } } int lca(int u, int v){ if(h[u] != h[v]){ if(h[u] < h[v]) swap(u, v); int k = h[u] - h[v]; F0Rd(i, __lg(k)+1) if((k >> i) & 1) u = up[u][i]; } if(u == v) return u; F0Rd(i, __lg(h[u])+1) if(up[u][i] != up[v][i]) u = up[u][i], v = up[v][i]; return up[u][0]; } void DFS(int u, int p = -1){ for(auto [v, e] : adj[u]) if(v != p){ DFS(v, u); cnt[u] += cnt[v]; } } void sol(void){ cin >> n >> m >> k; FOR(i, 1, n-1){ int u, v; cin >> u >> v; adj[u].pb(v,i), adj[v].pb(u,i); } dfs(1); FOR(i, 1, m){ int s; cin >> s; FOR(i, 1, s) cin >> idx[i]; sort(idx+1, idx+s+1, [&](const int &x, const int &y){ return num[x] < num[y]; }); FOR(i, 1, s-1){ cnt[idx[i]]++, cnt[idx[i+1]]++; cnt[lca(idx[i], idx[i+1])] -= 2; } } DFS(1); FOR(i, 1, n) if(cnt[i] >= k) ans.push_back(id[i]); sort(all(ans)); cout << sz(ans) << '\n'; for(int i : ans) cout << i << ' '; } signed main(void){ #define TASK "nhap" if(fopen(TASK".inp", "r")){ freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while(t--) sol(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n"; }

Compilation message (stderr)

railway.cpp: In function 'int main()':
railway.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(TASK".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...