結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー |
![]() |
提出日時 | 2020-08-07 23:07:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,021 bytes |
コンパイル時間 | 2,550 ms |
コンパイル使用メモリ | 205,520 KB |
最終ジャッジ日時 | 2025-01-12 18:01:29 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 1 |
other | AC * 5 WA * 13 RE * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M; cin >> N >> M; vec<int> A(M); set<int> s; for(int i=0;i<M;i++){ cin >> A[i]; A[i]--; s.insert(A[i]); } vvec<int> g(N); for(int i=0;i<N-1;i++){ int a,b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vec<int> dp(N); { auto dfs = [&](auto&& self,int cur,int par)->void{ bool exist = false; for(auto& to:g[cur]) if(to!=par){ self(self,to,cur); exist |= !dp[to]; } dp[cur] = exist; }; dfs(dfs,0,-1); } vec<int> dp2(N); vvec<int> child[2]; for(int i=0;i<2;i++) child[i] = vvec<int>(N); { auto dfs = [&](auto&& self,int cur,int par,int parg)->void{ int n = g[cur].size(); vec<int> L(n+1,0),R(n+1,0); for(int i=0;i<n;i++){ int to = g[cur][i]; L[i+1] = L[i] || !(to!=par? dp[to]:parg); } for(int i=n-1;i>=0;i--){ int to = g[cur][i]; R[i] = R[i+1] || !(to!=par? dp[to]:parg); } dp2[cur] = L[n]; for(int i=0;i<n;i++){ int to = g[cur][i]; child[(to!=par? dp[to]:parg)][cur].push_back(to); if(to==par) continue; self(self,to,cur,L[i]||R[i+1]); } }; dfs(dfs,0,-1,0); } int win = 0; for(int i=0;i<M;i++) win ^= dp2[A[i]]; if(!win){ cout << -1 << " " << -1 << "\n"; return 0; } assert(false); for(int i=0;i<M;i++){ for(auto& x:child[!dp2[A[i]]][A[i]]){ cout << i+1 << " " << x+1 << "\n"; return 0; } } }