답안 #433906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433906 2021-06-20T12:08:11 Z AmineWeslati Traffickers (RMI18_traffickers) C++14
0 / 100
3500 ms 11860 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

typedef string str; 

typedef pair<int,int>pi;
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmin(int &x, int y){x=min(x,y);}
//------------------------------------

const int MX=1e5;

int N; 
vi adj[MX];
set<pi> vec[MX];

vi par(MX);
void dfs(int u, int p, int dest){
	if(u==dest) return; 

	for(int v: adj[u]) if(v!=p){
		par[v]=u;
		dfs(v,u,dest);
	}

}

void add(int u, int v){
	dfs(u,u,v);

	int cur=v,n=0;

	vi cy; 
	while(1){
		n++;
		cy.pb(cur);
		if(cur==u) break;
		cur=par[cur];
	}
	reverse(all(cy));

	FOR(i,0,n){
		vec[cy[i]].insert({n,i});
	}
}

void del(int u, int v){
	dfs(u,u,v);

	int cur=v,n=0;

	vi cy; 
	while(1){
		n++;
		cy.pb(cur);
		if(cur==u) break;
		cur=par[cur];
	}
	reverse(all(cy));

	FOR(i,0,n){
		vec[cy[i]].erase({n,i});
	}
}

int main(){

	cin>>N; 
	FOR(i,0,N-1){
		int u,v; cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	int K; cin>>K;
	FOR(i,0,K){
		int u,v; cin>>u>>v;
		add(u,v);
	}

	/*FOR(i,1,N+1){
		for(auto x: vec[i]) cout << x.fi << ' ' << x.se << endl;
		cout << endl;
	}*/

	int Q; cin>>Q;
	while(Q--){
		int ty; cin>>ty;
		if(ty==1){
			int u,v; cin>>u>>v;
			add(u,v);
		}
		else if(ty==2){
			int u,v; cin>>u>>v;
			del(u,v);
		}
		else{
			int u,v,t,tt; cin>>u>>v>>t>>tt; 
			dfs(u,u,v);

			int cur=v,ans=0; 
			while(1){
				for(auto it: vec[cur]){
					int a=it.fi,b=it.se;
					int l=(t-b+a-1)/a,r=(tt-b)/a;
					ans+=max(0,r-l+1);
				}

				if(cur==u) break;
				cur=par[cur];
			}
			cout << ans << endl;
		}
		
	}



}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7756 KB Output isn't correct
2 Incorrect 45 ms 8056 KB Output isn't correct
3 Incorrect 35 ms 8028 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3551 ms 10788 KB Time limit exceeded
2 Execution timed out 3563 ms 10572 KB Time limit exceeded
3 Execution timed out 3562 ms 10920 KB Time limit exceeded
4 Execution timed out 3529 ms 10796 KB Time limit exceeded
5 Execution timed out 3564 ms 10684 KB Time limit exceeded
6 Execution timed out 3533 ms 10780 KB Time limit exceeded
7 Execution timed out 3526 ms 10744 KB Time limit exceeded
8 Execution timed out 3582 ms 10916 KB Time limit exceeded
9 Execution timed out 3586 ms 10836 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3595 ms 10704 KB Time limit exceeded
2 Execution timed out 3595 ms 11144 KB Time limit exceeded
3 Execution timed out 3561 ms 11560 KB Time limit exceeded
4 Execution timed out 3595 ms 10284 KB Time limit exceeded
5 Execution timed out 3595 ms 10104 KB Time limit exceeded
6 Execution timed out 3566 ms 11392 KB Time limit exceeded
7 Execution timed out 3540 ms 11860 KB Time limit exceeded
8 Execution timed out 3585 ms 11856 KB Time limit exceeded