Submission #876808

#TimeUsernameProblemLanguageResultExecution timeMemory
876808IvkosqnJail (JOI22_jail)C++14
0 / 100
2 ms6748 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int maxn = 120010; int n, m, s[maxn], f[maxn], used[maxn], bef[maxn], p[maxn]; vector<int> v[maxn], paths[maxn]; void dfs(int ver){ used[ver] = 1; for(int nb : v[ver]){ if(used[nb]) continue; bef[nb] = ver; dfs(nb); } } void read(){ cin >> n; for(int i = 1;i <= n;i++) v[i].clear(); for(int i = 1;i <= n - 1;i++){ int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } cin >> m; for(int i = 1;i <= m;i++){ cin >> s[i] >> f[i]; for(int j = 1;j <= n;j++) used[j] = 0; dfs(s[i]); int x = f[i]; paths[i].clear(); paths[i].push_back(x); while(x != s[i]){ x = bef[x]; paths[i].push_back(x); } reverse(paths[i].begin(), paths[i].end()); } } void solve(){ read(); for(int i = 0;i < n;i++){ bool flag = false; for(int k = 1;k <= m;k++){ if(paths[k].size() > i){ p[paths[k][i]]++; if(p[paths[k][i]] > 1) flag = true; } } for(int k = 1;k <= m;k++){ if(paths[k].size() > i) p[paths[k][i]] = 0; } if(flag){ cout << "No\n"; return; } } cout << "Yes\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

jail.cpp: In function 'void solve()':
jail.cpp:52:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |             if(paths[k].size() > i){
      |                ~~~~~~~~~~~~~~~~^~~
jail.cpp:59:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |             if(paths[k].size() > i)
      |                ~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...