提出 #1425431
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
set<int> pathAB;
set<int> hasA;
vector<int> adj[100005];
int cameFrom[100006];
bool visited[100005];
int n;
void gogo(int v){
visited[v] = true;
hasA.insert(v);
for(int i = 0; i < adj[v].size(); i++){
if(!visited[adj[v][i]] && pathAB.find(adj[v][i]) == pathAB.end()){
gogo(adj[v][i]);
}
}
}
int main(){
memset(cameFrom, 0, sizeof(cameFrom));
memset(visited, 0, sizeof(visited));
ios_base::sync_with_stdio(false);
cin >> n;
for(int i = 0; i < n-1; i++){
int a,b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
queue<int> q;
cameFrom[1] = -1;
q.push(1);
bool brk = false;
visited[1]= true;
while(q.size()){
int curr = q.back();
cout << curr << endl;
q.pop();
for(int i = 0; i < adj[curr].size(); i++){
if(!visited[adj[curr][i]]){
visited[adj[curr][i]]= true;
cameFrom[adj[curr][i]] = curr;
q.push(adj[curr][i]);
if(adj[curr][i] == n){
brk=true;
break;
}
}
}
if(brk)break;
}
int ff = n;
while(cameFrom[ff] != -1){
pathAB.insert(ff);
ff = cameFrom[ff];
}
pathAB.insert(1);
pathAB.insert(n);
memset(visited,false,sizeof(visited));
gogo(1);
int aSize = hasA.size() + (pathAB.size() - 1) / 2,
bSize = n - aSize;
if(aSize > bSize){
cout << "Fennec";
}else cout << "Snuke";
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Fennec VS. Snuke |
| ユーザ | polko |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 0 |
| コード長 | 1754 Byte |
| 結果 | WA |
| 実行時間 | 2104 ms |
| メモリ | 11520 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 400 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt |
| All | 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_example_01.txt | WA | 3 ms | 3072 KiB |
| 00_example_02.txt | WA | 3 ms | 3072 KiB |
| 01.txt | TLE | 2103 ms | 3072 KiB |
| 02.txt | TLE | 2103 ms | 3072 KiB |
| 03.txt | TLE | 2103 ms | 3072 KiB |
| 04.txt | TLE | 2103 ms | 3072 KiB |
| 05.txt | TLE | 2104 ms | 5760 KiB |
| 06.txt | TLE | 2104 ms | 5888 KiB |
| 07.txt | TLE | 2103 ms | 7808 KiB |
| 08.txt | TLE | 2104 ms | 5888 KiB |
| 09.txt | WA | 3 ms | 3072 KiB |
| 10.txt | TLE | 2104 ms | 5888 KiB |
| 11.txt | TLE | 2104 ms | 5888 KiB |
| 12.txt | TLE | 2104 ms | 6144 KiB |
| 13.txt | TLE | 2103 ms | 8320 KiB |
| 14.txt | TLE | 2104 ms | 6272 KiB |
| 15.txt | TLE | 2104 ms | 6272 KiB |
| 16.txt | WA | 211 ms | 11520 KiB |
| 17.txt | WA | 210 ms | 11520 KiB |
| 18.txt | WA | 214 ms | 11520 KiB |
| 19.txt | WA | 217 ms | 11520 KiB |