Submission #1871494


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b, t, l, r;
vector<vi> e(100000);
int d0[100000], dn[100000];

void dfs0(int v, int d) {
	d0[v] = d;
	rep(i,e[v].size()) {
		t = e[v][i];
		if (d0[t]==inf) dfs0(t, d+1);
	}
}

void dfsn(int v, int d) {
	dn[v] = d;
	rep(i,e[v].size()) {
		t = e[v][i];
		if (dn[t]==inf) dfsn(t, d+1);
	}
}

int main() {
	cin >> n;
	rep(i,n-1) {
		cin >> a >> b;
		a--, b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	
	// dfsで0からの最短距離とn-1からの最短距離を全ての点について求める
	// d0[i]<=dn[i]なら先手(Fennecくん)がそのマスを塗れる
	fill(d0, d0+n, inf);
	dfs0(0, 0);
	fill(dn, dn+n, inf);
	dfsn(n-1, 0);
	rep(i,n) {
		if (d0[i]<=dn[i]) l++;
		else r++;
	}
	if (l>r) cout << "Fennec" << ln;
	else cout << "Snuke" << ln;
}

Submission Info

Submission Time
Task D - Fennec VS. Snuke
User creep04
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2452 Byte
Status AC
Exec Time 48 ms
Memory 11264 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 2 ms 2560 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 35 ms 7168 KB
06.txt AC 38 ms 7424 KB
07.txt AC 35 ms 7168 KB
08.txt AC 38 ms 7296 KB
09.txt AC 2 ms 2560 KB
10.txt AC 32 ms 6016 KB
11.txt AC 38 ms 6144 KB
12.txt AC 32 ms 6528 KB
13.txt AC 37 ms 6528 KB
14.txt AC 37 ms 6528 KB
15.txt AC 37 ms 6528 KB
16.txt AC 41 ms 11136 KB
17.txt AC 48 ms 11136 KB
18.txt AC 41 ms 11136 KB
19.txt AC 39 ms 11264 KB