제출 #1013538

#제출 시각아이디문제언어결과실행 시간메모리
1013538ByeWorldRailway (BOI17_railway)C++14
100 / 100
221 ms48328 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") #define ll long long #define int long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) #define ld long double using namespace std; typedef pair<int,int> pii; typedef pair<pii, int> ipii; const int MAXN = 2e5+10; const int MAXA = 2e3+10; const int INF = 1e18+10; const int LOG = 19; const int MOD = 1e9+7; const int SQRT = 450; const vector<int> NOL = {}; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const vector<int> dx = {1, -1, 0, 0}; const vector<int> dy = {0, 0, 1, -1}; int n, m, k; vector <int> adj[MAXN]; int dep[MAXN], anc[MAXN][LOG+5], in[MAXN], tim; map<pii,int> edge; void dfs(int nw, int par){ dep[nw] = dep[par]+1; in[nw] = ++tim; anc[nw][0] = par; for(auto nx : adj[nw]){ if(nx==par) continue; dfs(nx, nw); } } int LCA(int x, int y){ if(dep[x] < dep[y]) swap(x, y); for(int i=LOG-1; i>=0; i--){ if(dep[anc[x][i]] >= dep[y]) x = anc[x][i]; } if(x == y) return x; for(int i=LOG-1; i>=0; i--){ if(anc[x][i] != anc[y][i]){ x = anc[x][i]; y = anc[y][i]; } } return anc[x][0]; } int cnt[MAXN]; void OUT(int nw, int par){ for(auto nx : adj[nw]){ if(nx==par) continue; OUT(nx, nw); cnt[nw] += cnt[nx]; } } signed main(){ cin >> n >> m >> k; for(int i=1; i<=n-1; i++){ int x, y; cin >> x >> y; edge[pii(x, y)] = edge[pii(y,x)] = i; adj[x].pb(y); adj[y].pb(x); } dfs(1, 0); for(int j=1; j<LOG; j++) for(int i=1; i<=n; i++) anc[i][j] = anc[ anc[i][j-1] ][j-1]; for(int i=1; i<=m; i++){ int num; cin >> num; vector <pii> inp; for(int xx=1; xx<=num; xx++){ int x; cin >> x; inp.pb({in[x], x}); } sort(inp.begin(), inp.end()); for(int j=1; j<inp.size(); j++){ int x = inp[j-1].se, y = inp[j].se; cnt[x]++; cnt[y]++; cnt[LCA(x,y)] -= 2; } int x = inp.back().se, y = inp[0].se; cnt[x]++; cnt[y]++; cnt[LCA(x,y)] -= 2; // vector <int> stac; // for(auto [in, x] : inp){ // if(stac.size() < 2) stac.pb(x); // else { // int depba = dep[LCA(stac.back(), x)]; // while(stac.size()>=2 && // dep[ LCA(stac.back(), stac[stac.size()-2]) ] >= depba){ // int p = stac.back(); stac.pop_back(); // int q = stac.back(); stac.pop_back(); // int lca = LCA(p, q); // // cout << "upd: " << p << ' ' << q << ' ' << lca << " p\n"; // cnt[p]++; cnt[q]++; cnt[lca] -= 2; // stac.pb(lca); // } // stac.pb(x); // } // } // while(stac.size()>=2){ // int p = stac.back(); stac.pop_back(); // int q = stac.back(); stac.pop_back(); // int lca = LCA(p, q); // // cout << "upd: " << p << ' ' << q << ' ' << lca << " p\n"; // cnt[p]++; cnt[q]++; cnt[lca] -= 2; // stac.pb(lca); // } } // for(int i=1; i<=n; i++) cout << cnt[i] << " p\n"; OUT(1, 0); vector <int> ANS; for(int i=1; i<=n; i++){ if(cnt[i] >= 2*k) ANS.pb(edge[pii(i, anc[i][0]) ]); } sort(ANS.begin(), ANS.end()); cout << ANS.size() << '\n'; for(auto in : ANS) cout << in << ' '; cout << '\n'; }

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

railway.cpp: In function 'int main()':
railway.cpp:82:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int j=1; j<inp.size(); j++){
      |                      ~^~~~~~~~~~~
#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...