AtCoder Grand Contest 005

Submission #1355499

Source codeソースコード

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

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

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状態 WA
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 AC 140 ms 25592 KB
doublestar1 AC 129 ms 24952 KB
doublestar2 AC 144 ms 25464 KB
doublestar3 AC 139 ms 24824 KB
doublestar4 AC 147 ms 25848 KB
doublestar5 AC 140 ms 25976 KB
doublestar6 AC 134 ms 24824 KB
doublestar7 AC 128 ms 24952 KB
example0 AC 5 ms 12544 KB
example1 AC 5 ms 12544 KB
example2 AC 5 ms 12544 KB
example3 AC 5 ms 12544 KB
example4 AC 5 ms 12544 KB
giri0 AC 153 ms 26240 KB
giri1 AC 158 ms 25344 KB
giri2 AC 154 ms 25344 KB
giri3 AC 160 ms 25216 KB
giri4 WA
giri5 AC 166 ms 25600 KB
giri6 AC 168 ms 25600 KB
giri7 WA
giri8 AC 171 ms 25344 KB
giri9 AC 157 ms 25600 KB
maxrand0 AC 160 ms 25600 KB
maxrand1 AC 158 ms 25472 KB
maxrand2 AC 164 ms 25728 KB
maxrand3 AC 153 ms 25344 KB
maxrand4 AC 151 ms 25088 KB
maxrand5 AC 166 ms 25088 KB
maxrand6 AC 153 ms 25088 KB
maxrand7 AC 158 ms 25472 KB
maxrand8 AC 152 ms 25088 KB
maxrand9 AC 155 ms 25472 KB
narashi0 AC 157 ms 24832 KB
narashi1 AC 162 ms 24960 KB
narashi2 AC 158 ms 25088 KB
narashi3 AC 158 ms 25344 KB
narashi4 AC 165 ms 25344 KB
narashi5 AC 160 ms 25472 KB
narashi6 AC 169 ms 25088 KB
narashi7 AC 161 ms 25728 KB
narashi8 AC 166 ms 25472 KB
narashi9 AC 157 ms 25088 KB
ok0 AC 182 ms 37372 KB
ok1 AC 174 ms 39164 KB
ok2 WA
ok3 AC 205 ms 39420 KB
ok4 AC 177 ms 30848 KB
ok5 AC 175 ms 33788 KB
ok6 AC 172 ms 34940 KB
ok7 AC 167 ms 30848 KB
ok8 WA
ok9 AC 169 ms 35324 KB
ouh0 AC 133 ms 27264 KB
ouh1 AC 157 ms 28544 KB
ouh2 AC 144 ms 29568 KB
ouh3 AC 156 ms 30336 KB
ouh4 AC 164 ms 29440 KB
ouh5 AC 153 ms 35708 KB
ouh6 AC 177 ms 37372 KB
ouh7 AC 154 ms 28800 KB
ouh8 AC 167 ms 34684 KB
ouh9 AC 163 ms 37500 KB
same0 AC 169 ms 25344 KB
same1 AC 162 ms 25216 KB
same2 AC 175 ms 25600 KB
same3 WA
same4 AC 156 ms 25088 KB
same5 AC 157 ms 25088 KB
same6 AC 160 ms 25344 KB
same7 AC 157 ms 25088 KB
same8 WA
same9 AC 165 ms 25600 KB
sameline0 AC 180 ms 38144 KB
sameline1 AC 190 ms 38656 KB
sameline2 AC 166 ms 34816 KB
sameline3 AC 190 ms 36480 KB
sameline4 AC 169 ms 37888 KB
sameline5 AC 179 ms 37760 KB
sameline6 AC 171 ms 33152 KB
sameline7 AC 183 ms 37248 KB
sameline8 AC 170 ms 35328 KB
sameline9 AC 184 ms 33408 KB
star0 AC 115 ms 26356 KB
star1 AC 107 ms 26228 KB
star2 AC 104 ms 26356 KB
star3 AC 114 ms 26228 KB
star4 AC 118 ms 26356 KB
star5 AC 116 ms 26484 KB
star6 AC 110 ms 26484 KB
star7 AC 115 ms 26228 KB
star8 AC 113 ms 26228 KB
star9 AC 122 ms 26740 KB
supersmall0 AC 5 ms 12544 KB
supersmall1 AC 5 ms 12544 KB
supersmall2 AC 5 ms 12544 KB
supersmall3 AC 5 ms 12544 KB
supersmall4 AC 5 ms 12544 KB
supersmall5 AC 5 ms 12544 KB
supersmall6 AC 5 ms 12544 KB
supersmall7 WA
supersmall8 AC 5 ms 12544 KB
supersmall9 AC 5 ms 12544 KB