結果
問題 |
No.1153 ねこちゃんゲーム
|
ユーザー |
|
提出日時 | 2025-07-30 18:54:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,490 bytes |
コンパイル時間 | 2,469 ms |
コンパイル使用メモリ | 203,576 KB |
実行使用メモリ | 51,668 KB |
最終ジャッジ日時 | 2025-07-30 18:54:48 |
合計ジャッジ時間 | 22,649 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 35 TLE * 1 -- * 4 |
ソースコード
//Date: 2025-07-29 13:18:22 #include <bits/stdc++.h> using namespace std; #define int long long #define P emplace_back #define CLEAR(a, v) memset(a, (v), sizeof(a)) #define pii pair<int, int> #define fi first #define se second #define rep(i, a, b) for(int i = (a); i <= (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i--) //char buf[1 << 20], *p1, *p2; //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++) inline int rd() { int s = 0, m = 0; char ch = getchar(); while(!isdigit(ch)) {if(ch == '-') m = 1; ch = getchar();} while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return m ? -s : s; } bool MBE; namespace SOLVER { const int N = 4e5 + 5; int n, m, tot, a[N], f[N], h[N], vis[N], sum; pii e[N], ans; vector<pii> g[N]; void dfs1(int u, int p, int las) { for(auto [v, id] : g[u]) if(v != p) dfs1(v, u, id); for(auto [v, id] : g[u]) if(v != p) vis[f[id]]++; if(p) while(vis[f[las]]) f[las]++; for(auto [v, id] : g[u]) if(v != p) vis[f[id]] = 0; } void dfs2(int u, int p, int las) { for(auto [v, id] : g[u]) if(v != p) vis[f[id]]++; if(p) vis[f[las ^ 1]]++; int cur = 0; while(vis[cur]) cur++; for(auto [v, id] : g[u]) if(v != p) f[id ^ 1] = vis[f[id]] == 1 && f[id] < cur ? f[id] : cur; for(auto [v, id] : g[u]) if(v != p) vis[f[id]] = 0; vis[f[las ^ 1]] = 0; for(auto [v, id] : g[u]) if(v != p) dfs2(v, u, id); } void MAIN() { n = rd(), m = rd(); ans = {n + 1, n + 1}; rep(i, 1, m) a[i] = rd(); rep(i, 1, n - 1) { int u = rd(), v = rd(); e[tot] = {u, v}, g[u].P(v, tot), tot++; e[tot] = {v, u}, g[v].P(u, tot), tot++; } dfs1(1, 0, 0), dfs2(1, 0, 0); // rep(i, 0, tot - 1) cerr << e[i].fi << ' ' << e[i].se << ' ' << f[i] << endl; rep(u, 1, n) { for(auto [v, id] : g[u]) vis[f[id]]++; while(vis[h[u]]) h[u]++; for(auto [v, id] : g[u]) vis[f[id]] = 0; } rep(i, 1, m) sum ^= h[a[i]]; rep(i, 1, m) for(auto [v, id] : g[a[i]]) if(!(sum ^ h[a[i]] ^ f[id])) ans = min(ans, {i, v}); if(ans.fi > n) puts("-1 -1"); else cout << ans.fi << ' ' << ans.se << endl; } } bool MED; signed main() { // freopen(".in", "r", stdin); freopen(".out", "w", stdout); // cin.tie(0), cout.tie(0), ios::sync_with_stdio(0); for(int tt = 1; tt; tt--) SOLVER::MAIN(); cerr << (&MBE - &MED) / 1024 << " KB, " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n"; return 0; }