Submission #1004293

#TimeUsernameProblemLanguageResultExecution timeMemory
1004293vjudge1Pastiri (COI20_pastiri)C++17
8 / 100
308 ms51908 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5+5; int n, k, dist[N], in[N]; vector<int> s, G[N], P[N], ans; void bfs() { queue<int> Q; for(int i = 1; i <= n; i ++) dist[i] = N + 20; for(int i : s) dist[i] = 0, Q.push(i); while(Q.size()) { int u = Q.front(); Q.pop(); for(int v: G[u]) if(dist[u] + 1 <= dist[v]) { P[v].push_back(u); in[u]++; if(dist[v] > dist[u] + 1) { dist[v] = dist[u] + 1; Q.push(v); } } } } void solve() { queue<int> Q; for(int i = 1; i <= n; i ++) if(in[i] == 0) Q.push(i); while(Q.size()) { int u = Q.front(); Q.pop(); if(P[u].size() == 1) { in[P[u][0]]--; if(in[P[u][0]] == 0) Q.push(P[u][0]); } else ans.push_back(u); } } int main() { cin >> n >> k; for(int i = 1; i < n; i ++) { int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } s.resize(k); for(int i = 0; i < k; i ++) cin >> s[i]; sort(s.begin(), s.end()); int cnt = 0; for(int i = 0; i < s.size(); i ++) { cnt++; if(i + 1 < s.size() && (s[i + 1] - s[i]) % 2 == 0) { ans.push_back((s[i + 1] + s[i]) / 2); i++; } else ans.push_back(s[i]); } cout << cnt << endl; for(int i : ans) cout << i << ' '; cout << endl; return 0; bfs(); solve(); cout << ans.size() << endl; for(int v : ans) cout << v << ' '; cout << endl; return 0; }

Compilation message (stderr)

pastiri.cpp: In function 'int main()':
pastiri.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for(int i = 0; i < s.size(); i ++)
      |                  ~~^~~~~~~~~~
pastiri.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |       if(i + 1 < s.size() && (s[i + 1] - s[i]) % 2 == 0) {
      |          ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...