답안 #643148

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

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

vector<int> path;

void dfs(int u, int p, int to) {
	for (auto v:adj[u]) {
		if (v==p) continue;
		if (v==to) {
			path.push_back(v);
			path.push_back(u);
			return;
		}
		dfs(v,u,to);
		if (path.back()==v) {
			path.push_back(u);
			return;
		}
	}
}

void solve() {

	int n; cin>>n;
	if (n>10000) exit(0);

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

	int K; cin>>K;
	forn(q,K) {
		int u,v; cin>>u>>v;
		dfs(u,0,v);
		vector<int> p=path;
		path.clear();
		reverse(p.begin(), p.end());
		for (int i=0; i<p.size(); ++i) {
			for (int j=0; 1ll*j*p.size()+i<10000; ++j) cnt[p[i]][j*p.size()+i]++;
		}
	}

	int Q; cin>>Q;
	forn(QQ,Q) {
		int q; cin>>q;
		if (q==1) {
			int u,v; cin>>u>>v;
			dfs(u,0,v);
			vector<int> p=path;
			path.clear();
			reverse(p.begin(), p.end());
			for (int i=0; i<p.size(); ++i) {
				for (int j=0; 1ll*j*p.size()+i<10000; ++j) cnt[p[i]][j*p.size()+i]++;
			}
		} else if (q==2) {
			int u,v; cin>>u>>v;
			dfs(u,0,v);
			vector<int> p=path;
			path.clear();
			reverse(p.begin(), p.end());
			for (int i=0; i<p.size(); ++i) {
				for (int j=0; 1ll*j*p.size()+i<10000; ++j) cnt[p[i]][j*p.size()+i]--;
			}
		} else {
			int u,v; cin>>u>>v;
			dfs(u,0,v);
			vector<int> p=path;
			path.clear();
			reverse(p.begin(), p.end());
			int ans=0;
			int l,r; cin>>l>>r;
			r=min(r,n);
			for (int i=0; i<p.size(); ++i) {
				for (int j=l; j<=r; ++j) ans+=cnt[p[i]][j];
			}
			cout<<ans<<'\n';
		}

	}

}

int32_t main() {
	solve();
	return 0;
}

Compilation message

traffickers.cpp: In function 'void solve()':
traffickers.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for (int i=0; i<p.size(); ++i) {
      |                 ~^~~~~~~~~
traffickers.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for (int i=0; i<p.size(); ++i) {
      |                  ~^~~~~~~~~
traffickers.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for (int i=0; i<p.size(); ++i) {
      |                  ~^~~~~~~~~
traffickers.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    for (int i=0; i<p.size(); ++i) {
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 520 ms 524288 KB Execution killed with signal 11
2 Incorrect 194 ms 392356 KB Output isn't correct
3 Runtime error 506 ms 524288 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 526 ms 524288 KB Execution killed with signal 11
2 Runtime error 679 ms 524296 KB Execution killed with signal 11
3 Runtime error 514 ms 524288 KB Execution killed with signal 11
4 Runtime error 528 ms 524288 KB Execution killed with signal 11
5 Runtime error 521 ms 524288 KB Execution killed with signal 11
6 Runtime error 523 ms 524288 KB Execution killed with signal 11
7 Runtime error 529 ms 524288 KB Execution killed with signal 11
8 Runtime error 535 ms 524288 KB Execution killed with signal 11
9 Runtime error 537 ms 524288 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Incorrect 160 ms 392320 KB Output isn't correct
2 Incorrect 162 ms 392416 KB Output isn't correct
3 Incorrect 152 ms 392284 KB Output isn't correct
4 Incorrect 149 ms 392312 KB Output isn't correct
5 Incorrect 149 ms 392348 KB Output isn't correct
6 Incorrect 152 ms 392492 KB Output isn't correct
7 Incorrect 149 ms 392300 KB Output isn't correct
8 Incorrect 151 ms 392360 KB Output isn't correct