結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-12 23:32:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,232 bytes |
| 記録 | |
| コンパイル時間 | 995 ms |
| コンパイル使用メモリ | 95,244 KB |
| 実行使用メモリ | 11,088 KB |
| 最終ジャッジ日時 | 2024-10-14 14:03:56 |
| 合計ジャッジ時間 | 2,921 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 4 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:8: warning: 'tar' may be used uninitialized [-Wmaybe-uninitialized]
35 | int tar;
| ^~~
ソースコード
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
using namespace std;
using ll = long long;
struct edge{
int from;
int to;
int co;
};
int main()
{
int n;
cin >> n;
vector<vector<int>> g(n);
vector<ll> cost(n, 1001001001);
vector<bool> stamp(n, false);
for(int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
int tar;
for(int i = 0; i < n; i++){
if(g[i].size() == 1){
tar = i;
break;
}
}
queue<int> q;
q.push(tar);
cost[tar] = 0;
vector<ll> ans;
stamp[tar] = true;
while(!q.empty()){
int u = q.front(); q.pop();
for(int v: g[u]){
if(stamp[v] == true) continue;
else stamp[v] = true;
cost[v] = cost[u]+1;
if(g[v].size() == 1) ans.push_back(cost[v]);
else q.push(v);
}
}
ll tmp = ans[0];
for(ll now : ans){
if(tmp != now){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}