Submission #2711311
Source Code Expand
#include <iostream> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <numeric> // accumulate(v.begin(), v.end(), 0) using namespace std; #define ll long long struct Edge{ int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} }; typedef vector< vector<Edge> > AdjList; AdjList graph; const int INF = 1e+8; vector<int> dist; bool bellman_ford(int n, int s){ // n: number of edges, s: source dist = vector<int>(n, INF); dist[s] = 0; for(int i=0; i<n; i++){ for(int v=0; v<n; v++){ for(int k=0; k<graph[v].size(); k++){ Edge e = graph[v][k]; if(dist[v] != INF && dist[e.to] > dist[v] + e.cost){ dist[e.to] = dist[v] + e.cost; if(i == n - 1) return true; } } } } return false; } int main(){ int N; cin >> N; graph = AdjList(N); for(int i=0; i<N-1; i++){ int from, to; cin >> from >> to; graph[from-1].push_back(Edge(to-1, 1)); graph[to-1].push_back(Edge(from-1, 1)); } vector<int> dist1(N); bellman_ford(N, 0); for(int i=0; i<N; i++) dist1[i] = dist[i]; vector<int> distN(N); bellman_ford(N, N-1); for(int i=0; i<N; i++) distN[i] = dist[i]; int countF = 0; int countS = 0; for(int i=0; i<N; i++) if(dist1[i] <= distN[i]) countF++; else countS++; if(countF >= countS) cout << "Fennec" << endl; else cout << "Sunuke" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Fennec VS. Snuke |
User | itohdak |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1487 Byte |
Status | WA |
Exec Time | 2104 ms |
Memory | 8320 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 1 ms | 256 KB |
00_example_02.txt | WA | 1 ms | 256 KB |
01.txt | WA | 1 ms | 256 KB |
02.txt | WA | 1 ms | 256 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | TLE | 2104 ms | 5760 KB |
06.txt | TLE | 2104 ms | 6144 KB |
07.txt | TLE | 2104 ms | 5760 KB |
08.txt | TLE | 2103 ms | 8320 KB |
09.txt | WA | 1 ms | 256 KB |
10.txt | TLE | 2104 ms | 6144 KB |
11.txt | TLE | 2104 ms | 6272 KB |
12.txt | TLE | 2104 ms | 6528 KB |
13.txt | TLE | 2104 ms | 6912 KB |
14.txt | TLE | 2104 ms | 6912 KB |
15.txt | TLE | 2104 ms | 6912 KB |
16.txt | TLE | 2103 ms | 6528 KB |
17.txt | TLE | 2104 ms | 6528 KB |
18.txt | TLE | 2104 ms | 6528 KB |
19.txt | TLE | 2104 ms | 6528 KB |