Submission #863536

#TimeUsernameProblemLanguageResultExecution timeMemory
863536RifalPastiri (COI20_pastiri)C++14
8 / 100
293 ms52672 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 1000000007 #define INF 900000000 //#define cin fin //#define cout fout //#define fi first //#define se second using namespace std; //ofstream fout("intel.out"); //ifstream fin("intel.in"); const int Max = 5e5 + 5; vector<int> v[Max]; bool ok[Max]; int arr[Max]; int cnt = 0; void dfs(int s, int p) { for(auto i : v[s]) { if(i != p) dfs(i,s); } arr[cnt] = s; cnt++; } int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n, k; cin >> n >> k; for(int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for(int i = 0; i < k; i++) { int x; cin >> x; ok[x] = 1; } dfs(1,0); vector<int> ans; pair<int,int> last = {-1,-1}; for(int i = 0; i < cnt; i++) { if(last.first != -1 && ok[arr[i]] == 1) { if((i-last.second)%2 == 0) { ans.push_back(arr[(i+last.second)/2]); last.first = -1; last.second = -1; } else { ans.push_back(last.first); last.first = arr[i]; last.second = i; } } else if(ok[arr[i]] == 1) { last.first = arr[i]; last.second = i; } } if(last.first != -1) { ans.push_back(last.first); } cout << ans.size() << endl; for(int i = 0; i < ans.size(); i++) cout << ans[i] << ' '; return 0; }

Compilation message (stderr)

pastiri.cpp: In function 'int main()':
pastiri.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0; i < ans.size(); i++) cout << ans[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...