Submission #1868153


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
int main() {
	int N;
	cin>>N;
	Graph G;
	for(int i=0;i<N;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(Edge(a,b,1));
		G[b].pb(Edge(b,a,1));
	}
	vint Pa,Pb;
	vector<Weight> Da,Db;
	shortestPath(G,0,Da,Pa);
	shortestPath(G,N-1,Db,Pb);

	int a=0,b=0;
	for(int i=0;i<N;i++){
		if(Da[i]<=Db[i])
			a++;
		else
			b++;
	}
	if(a>b)
		cout<<"Fennec"<<endl;
	else
		cout<<"Snuke"<<endl;
    return 0;
}

Submission Info

Submission Time
Task D - Fennec VS. Snuke
User takeo1116
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2709 Byte
Status AC
Exec Time 121 ms
Memory 9584 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 21
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 AC 1 ms 256 KB
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 84 ms 7664 KB
06.txt AC 83 ms 7664 KB
07.txt AC 76 ms 6768 KB
08.txt AC 80 ms 8176 KB
09.txt AC 1 ms 256 KB
10.txt AC 106 ms 8688 KB
11.txt AC 105 ms 8048 KB
12.txt AC 118 ms 8432 KB
13.txt AC 118 ms 8816 KB
14.txt AC 112 ms 9584 KB
15.txt AC 121 ms 8816 KB
16.txt AC 90 ms 8048 KB
17.txt AC 83 ms 7920 KB
18.txt AC 83 ms 7536 KB
19.txt AC 85 ms 7280 KB