답안 #782853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782853 2023-07-14T10:27:48 Z devariaota The Xana coup (BOI21_xanadu) C++17
0 / 100
38 ms 12620 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,u,v,ans;
vector<ll> adj[100100];
bool vis[100100];
ll a[100100];
void dfs(ll x) {
  vis[x] = true;
  for(auto i : adj[x]) {
    if(!vis[i]) {
      if(a[i] == 1) {
        a[min(n,i+1)] = a[min(n,i+1)] ^ 1 ^ 0;
        a[min(n,i+2)] = a[min(n,i+2)] ^ 1 ^ 0;
        ans++;
      }
      dfs(i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  FOR(1,i,n-1) {
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  a[0] = -1;
  FOR(1,i,n) {
    cin >> a[i];
  }
  dfs(1);
  FOR(1,i,a[i]) {
    if(a[i] == 1) {
      cout << "impossible" << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 12620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 12556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -