Submission #2857402
Source Code Expand
#include <iostream> #include <vector> #include <map> #include <unordered_map> #include <queue> #include <set> #include <algorithm> #include <string> #include <math.h> #include <limits.h> #include <stack> #include <complex> using namespace std; typedef long long ll; typedef pair<int, int> P; #define fs first #define sc second int n; vector<int> edge[100100]; // Pのfirstが最短距離、secondが頂点番号 int prev_node[100100]; int d[100100]; void dijkstra(int s){ priority_queue<P, vector<P>, greater<P> > que; fill(d, d+n, INT_MAX); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top(); que.pop(); int v = p.sc; if(d[v] < p.fs) continue; for(int i = 0; i < edge[v].size(); i++){ int e = edge[v][i]; //vからeへの道 if(d[e] > d[v] + 1){ d[e] = d[v] + 1; que.push(P(d[e], e)); prev_node[e] = v; } } } } ll child[100100]; ll tree_child_dfs(int s, int pre){ ll res = 0; for(int i = 0; i < edge[s].size(); i++){ if(edge[s][i] == pre) continue; res += tree_child_dfs(edge[s][i], s); } res++; child[s] = res; return res; } int main(){ cin >> n; for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; a--; b--; edge[a].push_back(b); edge[b].push_back(a); } dijkstra(0); tree_child_dfs(0, -1); int dis = (d[n-1] - 1) / 2; int node = n-1; for(int i = 0; i < dis; i++){ node = prev_node[node]; } ll sunuke = child[node]; ll fenec = n - child[node]; if(sunuke >= fenec){ cout << "Snuke" << endl; } else{ cout << "Fennec" << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Fennec VS. Snuke |
User | bomac1 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1886 Byte |
Status | AC |
Exec Time | 87 ms |
Memory | 15104 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 3 ms | 2688 KB |
00_example_02.txt | AC | 2 ms | 2560 KB |
01.txt | AC | 2 ms | 2560 KB |
02.txt | AC | 2 ms | 2560 KB |
03.txt | AC | 2 ms | 2560 KB |
04.txt | AC | 2 ms | 2560 KB |
05.txt | AC | 71 ms | 8576 KB |
06.txt | AC | 77 ms | 8960 KB |
07.txt | AC | 71 ms | 8576 KB |
08.txt | AC | 78 ms | 8832 KB |
09.txt | AC | 2 ms | 2560 KB |
10.txt | AC | 75 ms | 6764 KB |
11.txt | AC | 81 ms | 6912 KB |
12.txt | AC | 82 ms | 7120 KB |
13.txt | AC | 86 ms | 7408 KB |
14.txt | AC | 87 ms | 7368 KB |
15.txt | AC | 86 ms | 7400 KB |
16.txt | AC | 84 ms | 15104 KB |
17.txt | AC | 84 ms | 15104 KB |
18.txt | AC | 84 ms | 15104 KB |
19.txt | AC | 84 ms | 15104 KB |