結果
問題 | No.1424 Ultrapalindrome |
ユーザー | umezo |
提出日時 | 2021-03-12 23:29:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,465 bytes |
コンパイル時間 | 2,325 ms |
コンパイル使用メモリ | 211,528 KB |
実行使用メモリ | 12,484 KB |
最終ジャッジ日時 | 2024-10-14 16:26:36 |
合計ジャッジ時間 | 4,026 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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 | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 54 ms
8,192 KB |
testcase_10 | AC | 54 ms
8,192 KB |
testcase_11 | AC | 37 ms
6,784 KB |
testcase_12 | AC | 52 ms
7,936 KB |
testcase_13 | AC | 15 ms
5,248 KB |
testcase_14 | AC | 42 ms
7,040 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 32 ms
6,272 KB |
testcase_17 | AC | 39 ms
6,912 KB |
testcase_18 | AC | 32 ms
6,144 KB |
testcase_19 | AC | 49 ms
6,912 KB |
testcase_20 | AC | 13 ms
5,248 KB |
testcase_21 | AC | 37 ms
6,272 KB |
testcase_22 | AC | 25 ms
5,248 KB |
testcase_23 | AC | 7 ms
5,248 KB |
testcase_24 | AC | 11 ms
5,248 KB |
testcase_25 | AC | 10 ms
5,248 KB |
testcase_26 | AC | 57 ms
7,680 KB |
testcase_27 | WA | - |
testcase_28 | AC | 63 ms
8,960 KB |
testcase_29 | AC | 65 ms
9,472 KB |
testcase_30 | AC | 65 ms
12,484 KB |
testcase_31 | AC | 75 ms
12,484 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:66: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:45:7: note: 'mid' was declared here 45 | 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]; int dim[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)); } rep(i,n) dim[i]=G[i].size(); int cnt=0; int mid; rep(i,n){ if(dim[i]>2){ cnt++; mid=i; } } if(cnt>2){ cout<<"No"<<endl; return 0; } else if(cnt==0){ cout<<"Yes"<<endl; return 0; } int s=mid; 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}); } } } bool b=true; int tmp=-1; rep(i,n){ if(dim[i]!=1) continue; if(tmp==-1) tmp=dist[i]; else if(dist[i]!=tmp){ b=false; break; } } if(b) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }