Submission #242842

# Submission time Handle Problem Language Result Execution time Memory
242842 2020-06-29T11:35:31 Z moonrabbit2 Rigged Roads (NOI19_riggedroads) C++17
27 / 100
412 ms 65532 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int> tii;
typedef tuple<ll,ll,ll> tll;
typedef tuple<int,int,int,int> ti4;
typedef vector<vector<ll>> mat;
const ll mod=1e9+7,inf=1e18;
const int N=3e5+5,M=2e5+5,K=1e7+5;
int n,m,u[N],v[N],r[N],ok[N],cnt,ans[N];
vector<pll> g[N];
int in[N],pe[N],h[N],par[19][N],curp[N];
vector<int> V;
int clr(int u,int v){
	if(!u||h[u]<h[v]) return u;
	if(!in[pe[u]]) V.emplace_back(pe[u]);
	in[pe[u]]=1;
	return curp[u]=clr(curp[u],v);
}
void dfs(int u){
	for(auto [v,d] : g[u]) if(v!=par[0][u]){
		h[v]=h[u]+1; par[0][v]=u; curp[v]=u; pe[v]=d; dfs(v);
	}
}
int lca(int u,int v){
	if(h[u]>h[v]) swap(u,v);
	for(int bit=18;bit>=0;bit--) if((h[v]-h[u])&(1<<bit)){
		v=par[bit][v];
	}
	if(u==v) return u;
	for(int bit=18;bit>=0;bit--) if(par[bit][u]!=par[bit][v]){
		u=par[bit][u]; v=par[bit][v];
	}
	return par[0][u];
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>u[i]>>v[i];
	for(int i=1;i<n;i++){
		cin>>r[i];
		ok[r[i]]=1;
		g[u[r[i]]].emplace_back(v[r[i]],r[i]);
		g[v[r[i]]].emplace_back(u[r[i]],r[i]);
	}
	h[1]=1; dfs(1); in[0]=1;
	for(int bit=1;bit<19;bit++) for(int i=1;i<=n;i++){
		par[bit][i]=par[bit-1][par[bit-1][i]];
	}
	for(int i=1;i<=m;i++){
		if(ans[i]){
			cout<<ans[i]<<" "; continue;
		}
		if(ok[i]){
			in[i]=1; cout<<++cnt<<" "; continue;
		}
		int uv=lca(u[i],v[i]);
		clr(u[i],uv); clr(v[i],uv);
		sort(V.begin(),V.end());
		for(auto j : V) ans[j]=++cnt;
		V.clear();
		cout<<++cnt<<" ";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 9 ms 7680 KB Output is correct
5 Incorrect 9 ms 7680 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 23692 KB Output is correct
2 Correct 157 ms 29924 KB Output is correct
3 Correct 125 ms 17648 KB Output is correct
4 Correct 187 ms 51920 KB Output is correct
5 Correct 202 ms 53976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 180 ms 30900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 287 ms 55020 KB Output is correct
2 Correct 338 ms 61420 KB Output is correct
3 Correct 85 ms 22904 KB Output is correct
4 Correct 155 ms 30072 KB Output is correct
5 Correct 412 ms 65532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 39924 KB Output is correct
2 Incorrect 130 ms 29944 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 9 ms 7680 KB Output is correct
5 Incorrect 9 ms 7680 KB Output isn't correct
6 Halted 0 ms 0 KB -