結果

問題 No.1424 Ultrapalindrome
ユーザー umezoumezo
提出日時 2021-03-12 23:11:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,820 bytes
コンパイル時間 2,724 ms
コンパイル使用メモリ 208,544 KB
実行使用メモリ 16,908 KB
最終ジャッジ日時 2024-04-22 14:42:05
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 122 ms
10,368 KB
testcase_10 AC 120 ms
10,496 KB
testcase_11 AC 76 ms
8,320 KB
testcase_12 AC 91 ms
10,112 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 72 ms
8,576 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 55 ms
7,424 KB
testcase_17 AC 72 ms
8,448 KB
testcase_18 AC 50 ms
6,400 KB
testcase_19 AC 77 ms
6,912 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 48 ms
5,888 KB
testcase_22 AC 34 ms
5,376 KB
testcase_23 AC 10 ms
5,376 KB
testcase_24 AC 13 ms
5,376 KB
testcase_25 AC 13 ms
5,376 KB
testcase_26 AC 89 ms
7,552 KB
testcase_27 WA -
testcase_28 AC 71 ms
8,704 KB
testcase_29 WA -
testcase_30 AC 111 ms
16,908 KB
testcase_31 AC 124 ms
16,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_algobase.h:64,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/algorithm:60,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:51,
                 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/13.2.0/include/c++/13/bits/stl_pair.h:688:42: warning: 'mid' may be used uninitialized [-Wmaybe-uninitialized]
  688 |         : 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;
      |       ^~~

ソースコード

diff #

#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;
}
0