Submission #936006

# Submission time Handle Problem Language Result Execution time Memory
936006 2024-02-29T22:44:07 Z Litusiano Railway (BOI17_railway) C++17
0 / 100
215 ms 58300 KB
#include<bits/stdc++.h>
using namespace std;

struct LCA{
	int n;
	vector<vector<int>> jump;
	vector<int> dep;
	void dfs(int u, int p, int d, vector<vector<int>>& G, vector<int>& used){
		if(used[u]) return;
		dep[u] = d;
		used[u] = 1;
		jump[u][0] = p;
		for(int v : G[u]) dfs(v,u,d+1,G,used);
	}
	void init(int n1, vector<vector<int>>& G){
		n = n1;
		jump.assign(n+1,vector<int>(25,1));
		dep.assign(n+1,0);
		vector<int> used(n+1,0);
		dfs(1,1,0,G,used);
		for(int k = 1; k<25; k++){
			for(int u = 1; u<=n; u++){
				jump[u][k] = jump[jump[u][k-1]][k-1];
			}
		}
	}
	int LCAA(int a, int b){
		if(dep[a] > dep[b]) swap(a,b);
		int x = dep[b]-dep[a];
		for(int i = 0; i<25; i++){
			if(x & (1<<i)){
				b = jump[b][i];
			}
		}
		if(a == b) return a;
		for(int i = 24; i>=0; i--){
			if(jump[a][i] != jump[b][i]){
				a = jump[a][i];
				b = jump[b][i];
			}
		}
		return jump[a][0];
	}
};

int n,m,k;
vector<vector<int>> G;
vector<vector<int>> isLCA, FromU;
vector<set<int>> SmtoLG;
vector<int> used, fromk;

void dfs(int u){
	if(used[u]) return;
	used[u] = 1;
	for(int v : G[u]){
		if(used[v]) continue; //parent
		dfs(v);
		if(SmtoLG[v].size() > SmtoLG[u].size()) swap(SmtoLG[u], SmtoLG[v]); // the nodes for which the node can pass
		for(auto x : SmtoLG[v]) SmtoLG[u].insert(x);
	}
	for(auto x : FromU[u]) SmtoLG[u].insert(x); 
	for(auto x : isLCA[u]) SmtoLG[u].erase(x);
	fromk[u] = SmtoLG[u].size();
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m>>k;
	G.assign(n+1,vector<int>()); isLCA = G; FromU = isLCA;
	map<pair<int,int>,int> edge;
	for(int i = 1; i<n; i++){
		int u,v; cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
		pair<int,int> p = {u,v};
		edge[p] = i;
		swap(p.first,p.second);
		edge[p] = i;
	}
	LCA LC; LC.init(n,G);
	for(int i = 0; i<m; i++){
		int x; cin>>x;
		int a,b; cin>>a>>b;
		FromU[a].push_back(i); FromU[b].push_back(i);
		int lc = LC.LCAA(a,b);
		for(int j = 0; j<x-2; j++){
			int c; cin>>c;
			FromU[c].push_back(i);
			lc = LC.LCAA(lc,c);
		}
		isLCA[lc].push_back(i);
	}
	SmtoLG.resize(n+1);
	used.assign(n+1,0); fromk = used;
	dfs(1);
	vector<int> ans;
	for(int i = 2; i<=n; i++){
		//cout<<fromk[i]<<" ";
		if(fromk[i] > k){
			// cerr<<i<<" "<<LC.jump[i][0]<<endl;
			ans.push_back(edge[{i, LC.jump[i][0]}]);
		}
	}
	cout<<ans.size()<<endl;
	for(int i : ans) cout<<i<<" "; cout<<endl;
}

Compilation message

railway.cpp: In function 'int main()':
railway.cpp:106:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  106 |  for(int i : ans) cout<<i<<" "; cout<<endl;
      |  ^~~
railway.cpp:106:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  106 |  for(int i : ans) cout<<i<<" "; cout<<endl;
      |                                 ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 58300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 191 ms 51664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 191 ms 51664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -