AtCoder Grand Contest 005

Submission #1355498

Source codeソースコード

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

const int inf = 1e9;
int n, x, y, rp[100010], rd[100010], bp[100010], bd[100010], ans;
vector<int> re[100010], be[100010];

void T_T(){ puts("-1"); exit(0); }

void f(int t, int x, int pr, int de, int *p, int *d){
	d[x] = de;
	p[x] = pr;
	if(t){
		for(auto &i : be[x]){
			if(i != pr) f(t, i, x, de + 1, p, d);
		}
	}
	else{
		for(auto &i : re[x]){
			if(i != pr && i != y) f(t, i, x, de + 1, p, d);
		}
	}
}

int main(){
	scanf("%d%d%d", &n, &x, &y);
	auto in = [](int t){
		for(int i = 0, x, y; i < n - 1; i++){
			scanf("%d%d", &x, &y);
			(t ? be[x] : re[x]).push_back(y);
			(t ? be[y] : re[y]).push_back(x);
		}
	};
	in(0); in(1);
	f(1, y, 0, 0, bp, bd);
	fill(rd + 1, rd + n + 1, inf);
	f(0, x, 0, 0, rp, rd);
	for(int i = 1; i <= n; i++){
		for(auto &j : re[i]){
			int a = i, b = j;
			if(bd[a] > bd[b]) swap(a, b);
			if(bp[b] == a || bp[bp[b]] == a || bp[a] == bp[b]) continue;
			if(bd[a] >= rd[a] || bd[b] >= rd[b]) T_T();
		}
	}
	for(int i = 1; i <= n; i++) if(rd[i] < inf) ans = max(ans, 2 * bd[i]);
	printf("%d\n", ans);
}

Submission

Task問題 E - Sugigma: The Showdown
User nameユーザ名 Donghyun Kim
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 0
Source lengthソースコード長 1132 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:26:29: 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: In lambda function:
./Main.cpp:29:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0,example1,example2,example3,example4
All 0 / 1400 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
doublestar0 RE
doublestar1 RE
doublestar2 RE
doublestar3 RE
doublestar4 RE
doublestar5 RE
doublestar6 RE
doublestar7 RE
example0 AC 3 ms 6400 KB
example1 AC 3 ms 6400 KB
example2 AC 3 ms 6400 KB
example3 AC 3 ms 6400 KB
example4 AC 3 ms 6400 KB
giri0 RE
giri1 RE
giri2 RE
giri3 RE
giri4 RE
giri5 RE
giri6 RE
giri7 RE
giri8 RE
giri9 RE
maxrand0 RE
maxrand1 RE
maxrand2 RE
maxrand3 RE
maxrand4 RE
maxrand5 RE
maxrand6 RE
maxrand7 RE
maxrand8 RE
maxrand9 RE
narashi0 RE
narashi1 RE
narashi2 RE
narashi3 RE
narashi4 RE
narashi5 RE
narashi6 RE
narashi7 RE
narashi8 RE
narashi9 RE
ok0 RE
ok1 RE
ok2 RE
ok3 RE
ok4 RE
ok5 RE
ok6 RE
ok7 RE
ok8 RE
ok9 RE
ouh0 RE
ouh1 RE
ouh2 RE
ouh3 RE
ouh4 RE
ouh5 RE
ouh6 RE
ouh7 RE
ouh8 RE
ouh9 RE
same0 RE
same1 RE
same2 RE
same3 RE
same4 RE
same5 RE
same6 RE
same7 RE
same8 RE
same9 RE
sameline0 RE
sameline1 RE
sameline2 RE
sameline3 RE
sameline4 RE
sameline5 RE
sameline6 RE
sameline7 RE
sameline8 RE
sameline9 RE
star0 RE
star1 RE
star2 RE
star3 RE
star4 RE
star5 RE
star6 RE
star7 RE
star8 RE
star9 RE
supersmall0 AC 3 ms 6400 KB
supersmall1 AC 3 ms 6400 KB
supersmall2 AC 3 ms 6400 KB
supersmall3 AC 3 ms 6400 KB
supersmall4 AC 3 ms 6400 KB
supersmall5 AC 3 ms 6400 KB
supersmall6 AC 3 ms 6400 KB
supersmall7 WA
supersmall8 AC 3 ms 6400 KB
supersmall9 AC 3 ms 6400 KB