답안 #863533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863533 2023-10-20T14:28:38 Z Rifal Pastiri (COI20_pastiri) C++14
0 / 100
244 ms 41556 KB
#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

pastiri.cpp: In function 'int main()':
pastiri.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 41436 KB Output is correct
2 Incorrect 104 ms 41556 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 14428 KB Sheep 3030 not protected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 244 ms 30548 KB Output isn't correct
2 Halted 0 ms 0 KB -