| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 782876 | makanhulia | The Xana coup (BOI21_xanadu) | C++17 | 43 ms | 12364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 && i < n-1) {
a[i] = 0;
if(a[i+1] == 0) a[i+1] == 1;
else a[i+1] = 0;
if(a[i+2] == 0) a[i+2] = 1;
else a[i+2] = 0;
// cout << "i " << i << endl;
// cout << a[i] << " " << a[i+1] << " " << a[i+2] << endl;
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);
}
FOR(1,i,n) {
cin >> a[i];
}
adj[0].pb(1);
adj[1].pb(0);
dfs(0);
FOR(1,i,n) {
if(a[i] == 1) {
cout << "impossible" << endl;
return 0;
}
}
cout << ans << endl;
}
/*
7
1 2
2 3
3 4
4 5
5 6
6 7
0 0 1 1 0 1 0
*/컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
