This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int t, n;
vi a, b;
int main(){
cin>>n;
FOR(i,n-1){
int a, b;
cin>>a>>b;
}
a.resize(n+1);
FOR(i,n){
cin>>a[i+1];
}
a[0] = a[1];
int ans=0;
FORi(i,1,n-1){
// assume that everything before a[i-1]==0
if(a[i-1]==1){
a[i-1] = 1-a[i-1];
a[i] = 1-a[i];
a[i+1] = 1-a[i+1];
ans++;
}
}
if(a[n-1]+a[n-2]+a[n]!= 0) cout<<"impossible\n";
else cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |