#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
vector<vector<int>> adj(5001);
vector<vector<int>> cnt(5001,vector<int>(5001,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>5000) 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<5000; ++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<5000; ++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<5000; ++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 |
124 ms |
199372 KB |
Execution killed with signal 11 |
2 |
Incorrect |
71 ms |
98572 KB |
Output isn't correct |
3 |
Runtime error |
121 ms |
199456 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
98380 KB |
Output isn't correct |
2 |
Incorrect |
47 ms |
98452 KB |
Output isn't correct |
3 |
Incorrect |
43 ms |
98368 KB |
Output isn't correct |
4 |
Incorrect |
44 ms |
98376 KB |
Output isn't correct |
5 |
Incorrect |
46 ms |
98464 KB |
Output isn't correct |
6 |
Incorrect |
47 ms |
98372 KB |
Output isn't correct |
7 |
Incorrect |
40 ms |
98376 KB |
Output isn't correct |
8 |
Incorrect |
41 ms |
98364 KB |
Output isn't correct |
9 |
Incorrect |
45 ms |
98404 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
98380 KB |
Output isn't correct |
2 |
Incorrect |
66 ms |
98384 KB |
Output isn't correct |
3 |
Incorrect |
42 ms |
98380 KB |
Output isn't correct |
4 |
Incorrect |
43 ms |
98400 KB |
Output isn't correct |
5 |
Incorrect |
41 ms |
98392 KB |
Output isn't correct |
6 |
Incorrect |
41 ms |
98428 KB |
Output isn't correct |
7 |
Incorrect |
50 ms |
98380 KB |
Output isn't correct |
8 |
Incorrect |
44 ms |
98380 KB |
Output isn't correct |