Submission #1817926


Source Code Expand

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
const int N = 1e5 + 10;

struct edge{ int to, pre; } e[N << 1]; int l = 0, u[N];
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)

int n, X, Y, a[N], b[N], dep[N], fa[N];

void dfs(int x, int f) {
	reg(i,x) if (v != f) dep[v] = dep[x] + 1, fa[v] = x, dfs(v, x);
}

bool jump(int a, int b) {
	if (dep[a] < dep[b]) swap(a, b);
	if (fa[a] == b || fa[fa[a]] == b || fa[a] == fa[b]) return false;
	else return true;
}

vector<int> adj[N];
#define pb(a) push_back(a)

bool inf = false, win[N];
int ans = 0;
void chk(int x, int f, int d) {
	if (d >= dep[x]) return; else ans = max(ans, dep[x]);
	inf |= win[x]; int l = adj[x].size();
	Rep(j,l) if (adj[x][j] != f) chk(adj[x][j], x, d + 1);
}

int main() {
	scanf("%d%d%d",&n,&X,&Y);
	rep(i,1,n - 1) scanf("%d%d",a + i,b + i);
	rep(i,1,n - 1) {
		int a, b; scanf("%d%d",&a,&b);
		ins(a, b), ins(b, a);
	}
	dfs(Y, 0);
	rep(i,1,n - 1) 
		if (!jump(a[i], b[i])) 
			adj[a[i]].pb(b[i]), adj[b[i]].pb(a[i]);
		else win[a[i]] = win[b[i]] = true;
	chk(X, 0, 0);
	if (inf) printf("-1\n");
	else printf("%d\n",ans * 2);
	return 0;
}

Submission Info

Submission Time
Task E - Sugigma: The Showdown
User WuHongxun
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1407 Byte
Status RE
Exec Time 759 ms
Memory 269440 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&X,&Y);
                          ^
./Main.cpp:41:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i,1,n - 1) scanf("%d%d",a + i,b + i);
                                          ^
./Main.cpp:43:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d",&a,&b);
                                ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 5
AC × 15
RE × 88
Set Name Test Cases
Sample example0, example1, example2, example3, example4
All doublestar0, doublestar1, doublestar2, doublestar3, doublestar4, doublestar5, doublestar6, doublestar7, example0, example1, example2, example3, example4, giri0, giri1, giri2, giri3, giri4, giri5, giri6, giri7, giri8, giri9, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, narashi0, narashi1, narashi2, narashi3, narashi4, narashi5, narashi6, narashi7, narashi8, narashi9, ok0, ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8, ok9, ouh0, ouh1, ouh2, ouh3, ouh4, ouh5, ouh6, ouh7, ouh8, ouh9, same0, same1, same2, same3, same4, same5, same6, same7, same8, same9, sameline0, sameline1, sameline2, sameline3, sameline4, sameline5, sameline6, sameline7, sameline8, sameline9, star0, star1, star2, star3, star4, star5, star6, star7, star8, star9, supersmall0, supersmall1, supersmall2, supersmall3, supersmall4, supersmall5, supersmall6, supersmall7, supersmall8, supersmall9
Case Name Status Exec Time Memory
doublestar0 RE 126 ms 5504 KB
doublestar1 RE 299 ms 267008 KB
doublestar2 RE 274 ms 267008 KB
doublestar3 RE 126 ms 5504 KB
doublestar4 RE 126 ms 5504 KB
doublestar5 RE 127 ms 5504 KB
doublestar6 RE 329 ms 267136 KB
doublestar7 RE 260 ms 267136 KB
example0 AC 2 ms 4224 KB
example1 AC 2 ms 4224 KB
example2 AC 2 ms 4224 KB
example3 AC 2 ms 4224 KB
example4 AC 2 ms 4224 KB
giri0 RE 123 ms 5376 KB
giri1 RE 133 ms 5376 KB
giri2 RE 759 ms 5376 KB
giri3 RE 125 ms 5376 KB
giri4 RE 124 ms 5376 KB
giri5 RE 123 ms 5376 KB
giri6 RE 123 ms 5376 KB
giri7 RE 124 ms 5376 KB
giri8 RE 123 ms 5248 KB
giri9 RE 122 ms 5248 KB
maxrand0 RE 123 ms 5248 KB
maxrand1 RE 123 ms 5248 KB
maxrand2 RE 123 ms 5376 KB
maxrand3 RE 123 ms 5248 KB
maxrand4 RE 123 ms 5376 KB
maxrand5 RE 122 ms 5376 KB
maxrand6 RE 285 ms 267392 KB
maxrand7 RE 124 ms 5376 KB
maxrand8 RE 123 ms 5376 KB
maxrand9 RE 123 ms 5376 KB
narashi0 RE 125 ms 5376 KB
narashi1 RE 123 ms 5376 KB
narashi2 RE 123 ms 5376 KB
narashi3 RE 123 ms 5376 KB
narashi4 RE 123 ms 5376 KB
narashi5 RE 123 ms 5376 KB
narashi6 RE 123 ms 5376 KB
narashi7 RE 123 ms 5248 KB
narashi8 RE 124 ms 5376 KB
narashi9 RE 124 ms 5376 KB
ok0 RE 124 ms 5376 KB
ok1 RE 124 ms 5376 KB
ok2 RE 124 ms 5376 KB
ok3 RE 125 ms 5376 KB
ok4 RE 123 ms 5248 KB
ok5 RE 124 ms 5376 KB
ok6 RE 120 ms 5120 KB
ok7 RE 124 ms 5376 KB
ok8 RE 125 ms 5376 KB
ok9 RE 125 ms 5376 KB
ouh0 RE 293 ms 267520 KB
ouh1 RE 122 ms 5248 KB
ouh2 RE 121 ms 5248 KB
ouh3 RE 126 ms 5376 KB
ouh4 RE 302 ms 267392 KB
ouh5 RE 125 ms 5376 KB
ouh6 RE 120 ms 4992 KB
ouh7 RE 275 ms 267520 KB
ouh8 RE 277 ms 267392 KB
ouh9 RE 125 ms 5376 KB
same0 RE 123 ms 5248 KB
same1 RE 123 ms 5376 KB
same2 RE 123 ms 5248 KB
same3 RE 126 ms 5248 KB
same4 RE 123 ms 5376 KB
same5 RE 123 ms 5376 KB
same6 RE 123 ms 5376 KB
same7 RE 123 ms 5376 KB
same8 RE 264 ms 269440 KB
same9 RE 123 ms 5248 KB
sameline0 RE 123 ms 5376 KB
sameline1 RE 122 ms 5376 KB
sameline2 RE 123 ms 5376 KB
sameline3 RE 123 ms 5376 KB
sameline4 RE 122 ms 5376 KB
sameline5 RE 124 ms 5376 KB
sameline6 RE 123 ms 5376 KB
sameline7 RE 123 ms 5248 KB
sameline8 RE 123 ms 5376 KB
sameline9 RE 123 ms 5248 KB
star0 RE 351 ms 5760 KB
star1 RE 272 ms 267904 KB
star2 RE 268 ms 267904 KB
star3 RE 299 ms 267776 KB
star4 RE 311 ms 5760 KB
star5 RE 357 ms 267264 KB
star6 RE 270 ms 267904 KB
star7 RE 263 ms 267648 KB
star8 RE 376 ms 267008 KB
star9 RE 140 ms 5760 KB
supersmall0 AC 2 ms 4224 KB
supersmall1 AC 2 ms 4224 KB
supersmall2 AC 2 ms 4224 KB
supersmall3 AC 2 ms 4224 KB
supersmall4 AC 2 ms 4224 KB
supersmall5 AC 2 ms 4224 KB
supersmall6 AC 2 ms 4224 KB
supersmall7 AC 2 ms 4224 KB
supersmall8 AC 2 ms 4224 KB
supersmall9 AC 2 ms 4224 KB