Submission #2117655


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>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#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 pair<ll,ll> pll;
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;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint node[SIZE];
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		node[a].pb(b);
		node[b].pb(a);
	}
	int K;
	cin>>K;
	int num[SIZE]={};
	for(int i=0;i<N;i++)
		num[i]=INF;
	priority_queue<pint,vector<pint>,greater<pint>> que;
	for(int i=0;i<K;i++){
		int v,p;
		cin>>v>>p;
		v--;
		num[v]=p;
		que.push(mp(p,v));
	}
	while(que.size()){
		int v,p;
		tie(p,v)=que.top();
		que.pop();
		for(int i:node[v]){
			if(num[i]==INF){
				num[i]=p+1;
				que.push(mp(p+1,i));
			}
			else if(num[i]!=num[v]+1 && num[i]!=num[v]-1){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<N;i++)
		cout<<num[i]<<endl;
	return 0;
}

Submission Info

Submission Time
Task E - Integers on a Tree
User takeo1116
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1617 Byte
Status AC
Exec Time 303 ms
Memory 7924 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 39
Set Name Test Cases
sample sample_01.txt, sample_02.txt, sample_03.txt
All binary_01.txt, binary_02.txt, hand_01.txt, hand_02.txt, hand_03.txt, kary_01.txt, kary_02.txt, kary_03.txt, line_01.txt, line_02.txt, line_03.txt, line_04.txt, line_05.txt, line_06.txt, random0_01.txt, random1_01.txt, random1_02.txt, random1_03.txt, random1_04.txt, random1_05.txt, random1_06.txt, random1_07.txt, random1_08.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random3_01.txt, random3_02.txt, random4_01.txt, random4_02.txt, random4_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, star_01.txt, star_02.txt
Case Name Status Exec Time Memory
binary_01.txt AC 260 ms 7288 KB
binary_02.txt AC 77 ms 6144 KB
hand_01.txt AC 2 ms 2944 KB
hand_02.txt AC 2 ms 2944 KB
hand_03.txt AC 2 ms 2944 KB
kary_01.txt AC 69 ms 6272 KB
kary_02.txt AC 229 ms 7164 KB
kary_03.txt AC 67 ms 6144 KB
line_01.txt AC 79 ms 6528 KB
line_02.txt AC 221 ms 6784 KB
line_03.txt AC 222 ms 6784 KB
line_04.txt AC 245 ms 7036 KB
line_05.txt AC 67 ms 6144 KB
line_06.txt AC 94 ms 6528 KB
random0_01.txt AC 100 ms 6784 KB
random1_01.txt AC 236 ms 6912 KB
random1_02.txt AC 240 ms 6912 KB
random1_03.txt AC 254 ms 7040 KB
random1_04.txt AC 280 ms 7292 KB
random1_05.txt AC 236 ms 6912 KB
random1_06.txt AC 241 ms 6912 KB
random1_07.txt AC 243 ms 6912 KB
random1_08.txt AC 303 ms 7800 KB
random2_01.txt AC 71 ms 6144 KB
random2_02.txt AC 76 ms 6144 KB
random2_03.txt AC 71 ms 6144 KB
random2_04.txt AC 75 ms 6272 KB
random2_05.txt AC 102 ms 6784 KB
random2_06.txt AC 137 ms 7292 KB
random3_01.txt AC 71 ms 6144 KB
random3_02.txt AC 110 ms 6784 KB
random4_01.txt AC 234 ms 6912 KB
random4_02.txt AC 235 ms 6912 KB
random4_03.txt AC 243 ms 6912 KB
sample_01.txt AC 3 ms 2944 KB
sample_02.txt AC 2 ms 2944 KB
sample_03.txt AC 3 ms 2944 KB
star_01.txt AC 243 ms 7924 KB
star_02.txt AC 82 ms 7288 KB