답안 #643162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643162 2022-09-21T10:57:55 Z TimDee Traffickers (RMI18_traffickers) C++17
0 / 100
139 ms 199508 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
//#define int long long

vector<vector<int>> adj(5001);
vector<vector<int>> cnt(5001,vector<int>(5001,0));

int path[5001];
int ptr=0;

void dfs(int u, int p, int to) {
	for (auto v:adj[u]) {
		if (v==p) continue;
		if (v==to) {
			path[ptr++]=v;
			path[ptr++]=u;
			return;
		}
		dfs(v,u,to);
		if (ptr && path[ptr-1]==v) {
			path[ptr++]=u;
			return;
		}
	}
}

void solve() {

	int n; cin>>n;
	//if (n>5000) exit(0);

	forn(i,n-1) {
		int u,v; cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for (int i=0; i<=5000; ++i) {
		path[i]=0;
	}

	int K; cin>>K;
	forn(q,K) {
		int u,v; cin>>u>>v;
		ptr=0;
		dfs(u,0,v);
		for (int l=0, r=ptr-1; l<r; ++l, --r) {
			swap(path[l],path[r]);
		}
		for (int i=0; i<ptr; ++i) {
			for (int j=0; j*ptr+i<5000; ++j) cnt[path[i]][j*ptr+i]++;
		}
	}

	int Q; cin>>Q;
	forn(QQ,Q) {
		int q; cin>>q;
		if (q==1) {
			int u,v; cin>>u>>v;
			ptr=0;
			dfs(u,0,v);
			for (int l=0, r=ptr-1; l<r; ++l, --r) {
				swap(path[l],path[r]);
			}
			for (int i=0; i<ptr; ++i) {
				for (int j=0; j*ptr+i<5000; ++j) cnt[path[i]][j*ptr+i]++;
			}
		} else if (q==2) {
			int u,v; cin>>u>>v;
			ptr=0;
			dfs(u,0,v);
			for (int l=0, r=ptr-1; l<r; ++l, --r) {
				swap(path[l],path[r]);
			}
			for (int i=0; i<ptr; ++i) {
				for (int j=0; j*ptr+i<5000; ++j) cnt[path[i]][j*ptr+i]--;
			}
		} else {
			int u,v; cin>>u>>v;
			ptr=0;
			dfs(u,0,v);
			for (int l=0, r=ptr-1; l<r; ++l, --r) {
				swap(path[l],path[r]);
			}
			int ans=0;
			int l,r; cin>>l>>r;
			for (int i=0; i<ptr; ++i) {
				for (int j=l; j<=r; ++j) ans+=cnt[path[i]][j];
			}
			cout<<ans<<'\n';
		}

	}

}

int32_t main() {
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 98436 KB Output isn't correct
2 Incorrect 73 ms 98568 KB Output isn't correct
3 Incorrect 65 ms 98460 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 199400 KB Execution killed with signal 11
2 Runtime error 139 ms 199408 KB Execution killed with signal 11
3 Runtime error 130 ms 199400 KB Execution killed with signal 11
4 Runtime error 121 ms 199500 KB Execution killed with signal 11
5 Runtime error 130 ms 199480 KB Execution killed with signal 11
6 Runtime error 117 ms 199416 KB Execution killed with signal 11
7 Runtime error 126 ms 199464 KB Execution killed with signal 11
8 Runtime error 119 ms 199416 KB Execution killed with signal 11
9 Runtime error 121 ms 199504 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 128 ms 199500 KB Execution killed with signal 11
2 Runtime error 124 ms 199496 KB Execution killed with signal 11
3 Runtime error 121 ms 199508 KB Execution killed with signal 11
4 Runtime error 120 ms 199496 KB Execution killed with signal 11
5 Runtime error 134 ms 199448 KB Execution killed with signal 11
6 Runtime error 125 ms 199416 KB Execution killed with signal 11
7 Runtime error 125 ms 199468 KB Execution killed with signal 11
8 Runtime error 126 ms 199444 KB Execution killed with signal 11