結果
問題 | No.1424 Ultrapalindrome |
ユーザー | umezo |
提出日時 | 2021-03-12 23:11:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,820 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 218,028 KB |
実行使用メモリ | 16,784 KB |
最終ジャッジ日時 | 2024-10-14 13:47:35 |
合計ジャッジ時間 | 4,611 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | WA | - |
testcase_09 | AC | 101 ms
10,368 KB |
testcase_10 | AC | 89 ms
10,496 KB |
testcase_11 | AC | 60 ms
8,320 KB |
testcase_12 | AC | 73 ms
9,984 KB |
testcase_13 | AC | 22 ms
5,248 KB |
testcase_14 | AC | 59 ms
8,704 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 45 ms
7,680 KB |
testcase_17 | AC | 56 ms
8,448 KB |
testcase_18 | AC | 40 ms
6,528 KB |
testcase_19 | AC | 55 ms
6,912 KB |
testcase_20 | AC | 13 ms
5,248 KB |
testcase_21 | AC | 43 ms
6,016 KB |
testcase_22 | AC | 27 ms
5,248 KB |
testcase_23 | AC | 8 ms
5,248 KB |
testcase_24 | AC | 11 ms
5,248 KB |
testcase_25 | AC | 11 ms
5,248 KB |
testcase_26 | AC | 67 ms
7,424 KB |
testcase_27 | WA | - |
testcase_28 | AC | 63 ms
8,704 KB |
testcase_29 | WA | - |
testcase_30 | AC | 99 ms
16,780 KB |
testcase_31 | AC | 115 ms
16,784 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/specfun.h:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/cmath:1935, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41, from main.cpp:5: In constructor 'constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = int&; _U2 = int&; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = long long int; _T2 = int]', inlined from 'int main()' at main.cpp:97:11: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_pair.h:535:42: warning: 'mid' may be used uninitialized [-Wmaybe-uninitialized] 535 | : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp: In function 'int main()': main.cpp:85:7: note: 'mid' was declared here 85 | int mid; | ^~~
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const int INF=1e9; struct Edge{ int to; int w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector<vector<Edge>>; using pli=pair<ll,int>; int dist[100010]; template<class T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ int n; cin>>n; Graph G(n); rep(i,n-1){ int a,b; cin>>a>>b; a--,b--; G[a].push_back(Edge(b,1)); G[b].push_back(Edge(a,1)); } int x=-1,y=-1; set<int> se; rep(i,n){ if(G[i].size()==1){ if(x==-1) x=i; else if(y==-1) y=i; se.insert(i); } } if(se.size()==2){ cout<<"Yes"<<endl; return 0; } int s=x; rep(i,n) dist[i]=INF; dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } int di=dist[y]; if(di%2==1){ cout<<"No"<<endl; return 0; } int mid; rep(i,n){ if(dist[i]==di/2){ mid=i; break; } } s=mid; rep(i,n) dist[i]=INF; dist[s]=0; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } bool b=true; for(auto p:se){ if(dist[p]!=di/2) b=false; } if(b) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }