結果
| 問題 |
No.1424 Ultrapalindrome
|
| コンテスト | |
| ユーザー |
GRMN
|
| 提出日時 | 2021-05-02 22:02:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 1,834 bytes |
| コンパイル時間 | 4,116 ms |
| コンパイル使用メモリ | 257,972 KB |
| 最終ジャッジ日時 | 2025-01-21 06:03:39 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/c++allocator.h:33,
from /usr/include/c++/13/bits/allocator.h:46,
from /usr/include/c++/13/string:43,
from /usr/include/c++/13/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
from main.cpp:1:
In member function ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]’,
inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]’ at /usr/include/c++/13/bits/alloc_traits.h:538:17,
inlined from ‘void std::deque<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/13/bits/stl_deque.h:1543:30,
inlined from ‘void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]’ at /usr/include/c++/13/bits/stl_queue.h:286:20,
inlined from ‘int main()’ at main.cpp:50:13:
/usr/include/c++/13/bits/new_allocator.h:191:11: warning: ‘id’ may be used uninitialized [-Wmaybe-uninitialized]
191 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:33:15: note: ‘id’ was declared here
33 | int tmp=0,id;
| ^~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define fi first
#define se second
#define re0 return 0
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
constexpr ll inf = 2e9;
constexpr ll llinf = 9e18;
//constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;
const double pai=acos(-1);
int main() {
//cout<<fixed<<setprecision(15);
int n;cin>>n;
vector<vector<int>> g(n);
rep(i,n-1){
int a,b;cin>>a>>b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
int tmp=0,id;
rep(i,n){
int a=g[i].size();
if(a>tmp){
tmp=a;
id=i;
}
}
if(tmp==1||tmp==2){
cout<<"Yes"<<endl;
re0;
}
//cout<<id<<endl;
vector<int> vec(n),vec1(n);
vector<int> d(n,-1);
queue<int> que;
d[id]=0;
que.push(id);
while(!que.empty()){
int v=que.front();que.pop();
for(auto u:g[v]){
if(d[u]!=-1)continue;
d[u]=d[v]+1;
que.push(u);
if(g[u].size()==1)vec[u]=1,vec1[v]++;
}
}
//rep(i,n)cout<<d[i]<<endl;
set<int> st;
rep(i,n){
if(vec[i])st.insert(d[i]);
}
bool ok=true;
if(st.size()!=1)ok=false;
rep(i,n){
for(auto u:g[i]){
if(vec[i]&&vec1[u]>1&&u!=id)ok=false;
}
}
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
GRMN