Submission #643150

#TimeUsernameProblemLanguageResultExecution timeMemory
643150TimDeeTraffickers (RMI18_traffickers)C++17
0 / 100
124 ms199456 KiB
#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 (stderr)

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) {
      |                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...