Submission #1515926
Source Code Expand
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <assert.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define F first
#define S second
#define qq queue
#define dq deque
#define vc vector
#define INF ((int)(2e9))
#define LINF ((int)(1e18))
#define fir for( int i = 1 ; i <= n ; i++ )
#define fjr for( int j = 1 ; j <= n ; j++ )
#define fkr for( int k = 1 ; k <= n ; k++ )
#define firx( _x ) for( int i = 1 ; i <= _x ; i++ )
#define fjrx( _x ) for( int j = 1 ; j <= _x ; j++ )
#define fkrx( _x ) for( int k = 1 ; k <= _x ; k++ )
#define out cout <<
#define ln << endl
#define pb push_back
#define mp make_pair
#define _tp template
#define _tyn typename
#define pf push_front
#define itor iterator
#define mp make_pair
#define sint short int
#define ull unsigned long long
#define pq priority_queue
#define pii pair<int,int>
#define uint unsigned int
#define ll long long
#define B out "BreakPoint\n";
#define read(_num) scanf("%d",&_num)
#define ms(_data) memset(_data,0,sizeof(_data))
#define fin(_filename) freopen(_filename,"r",stdin)
#define fout(_filename) freopen(_filename,"w",stdout)
#define read2(_num1,_num2) scanf("%d %d",&_num1,&_num2)
#define msn(_data,_num) memset(_data,_num,sizeof(_data))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define read3(_num1,_num2,_num3) scanf("%d %d %d",&_num1,&_num2,&_num3)
using namespace std;
_tp<_tyn T>void mymax( T &_a , T _b ){ if( _a < _b ) _a = _b; }
_tp<_tyn T>void mymin( T &_a , T _b ){ if( _a > _b ) _a = _b; }
#define MAXN 100100
int n , k;
int val[MAXN];
#define _SHOW_ 0
#define _SHOW_PIIPLUS_ ( _SHOW_ & 1 )
#define _SHOW_MEM_ ( _SHOW_ & 1 )
void no(){
printf( "No\n" );
exit( 0 );
}
bool valuable( pii p1 ){
return p1.F <= p1.S;
}
pii operator+( pii p1 , pii p2 ){ // '+' means ∩(交集)
pii ret;
if( !valuable( p1 ) || !valuable( p2 ) )
ret = mp( INF , -INF );
else{
if( p1.F > p2.F )
swap( p1 , p2 );
if( p1.S < p2.F )
ret = mp( INF , -INF );
else
ret = mp( p2.F , min( p1.S , p2.S ) );
}
return ret;
}
vc<int> e[MAXN];
bool vis[MAXN];
//Check the odd/even
void check_jiou( int pos , int fa , int need ){ //need 0:odd 1:even -1:uknown
if( val[pos] != -1 ){
if( ( val[pos] & 1 ) != need && need != -1 )
no();
else need = ( val[pos] & 1 ) ^ 1;
}else
if( need != -1 )
need ^= 1;
for( uint i = 0 ; i < e[pos].size() ; i++ )
if( e[pos][i] != fa )
check_jiou( e[pos][i] , pos , need );
}
//Check the qujian
pii mem[MAXN];
pii check_qujian( int pos , int fa ){
pii ret;
if( val[pos] == -1 ) ret = mp( -INF , INF );
else ret = mp( val[pos] , val[pos] );
for( uint i = 0 ; i < e[pos].size() ; i++ )
if( e[pos][i] != fa ){
pii sonret = check_qujian( e[pos][i] , pos );
sonret.F--; sonret.S++;
ret = ret + sonret;
if( !valuable( ret ) )
no();
}
mem[pos] = ret;
return ret;
}
void xout( pii p1 ){
cout << "( " << p1.F << " , " << p1.S << " )\n";
}
//Print the ans
int ans[MAXN];
void getpath( int pos , int fa , pii now ){
if( _SHOW_PIIPLUS_ ){
cout << endl;
xout( now );
xout( mem[pos] );
xout( now+mem[pos] );
cout << endl;
}
now = now + mem[pos];
ans[pos] = now.F;
now.F--; now.S++;
for( uint i = 0 ; i < e[pos].size() ; i++ )
if( e[pos][i] != fa )
getpath( e[pos][i] , pos , now );
}
int main(){
#ifndef ONLINE_JUDGE
fin( "int.txt" );
#endif
msn( val , -1 );
read( n );
firx( n - 1 ){
int a , b;
read2( a , b );
e[a].pb( b );
e[b].pb( a );
}
read( k );
firx( k ){
int id , num;
read2( id , num );
val[id] = num;
}
check_jiou( 1 , -1 , -1);
check_qujian( 1 , -1 );
printf( "Yes\n" );
if( _SHOW_MEM_ )
for( int i = 1 ; i <= n ; i++ )
cout << i << " | " << mem[i].F << " " << mem[i].S << endl;
getpath( 1 , -1 , mem[1] );
for( int i = 1 ; i <= n ; i++ )
printf( "%d\n",ans[i] );
return 0;
}
Submission Info
Submission Time
2017-08-16 15:45:50+0900
Task
E - Integers on a Tree
User
interestingLSY
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
4133 Byte
Status
WA
Exec Time
3 ms
Memory
2944 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:147:19: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
fin( "int.txt" );
^
./Main.cpp:152:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
read( n );
^
./Main.cpp:155:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
read2( a , b );
^
./Main.cpp:160:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
read( k );
^
./Main.cpp:163:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
read2( id , num );
^
Judge Result
Set Name
sample
All
Score / Max Score
0 / 0
0 / 800
Status
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
WA
2 ms
2944 KB
binary_02.txt
WA
2 ms
2944 KB
hand_01.txt
WA
2 ms
2944 KB
hand_02.txt
WA
2 ms
2944 KB
hand_03.txt
WA
2 ms
2944 KB
kary_01.txt
WA
2 ms
2944 KB
kary_02.txt
WA
2 ms
2944 KB
kary_03.txt
WA
2 ms
2944 KB
line_01.txt
WA
2 ms
2944 KB
line_02.txt
WA
2 ms
2944 KB
line_03.txt
WA
2 ms
2944 KB
line_04.txt
WA
2 ms
2944 KB
line_05.txt
WA
2 ms
2944 KB
line_06.txt
WA
3 ms
2944 KB
random0_01.txt
WA
2 ms
2944 KB
random1_01.txt
WA
2 ms
2944 KB
random1_02.txt
WA
2 ms
2944 KB
random1_03.txt
WA
2 ms
2944 KB
random1_04.txt
WA
2 ms
2944 KB
random1_05.txt
WA
3 ms
2944 KB
random1_06.txt
WA
2 ms
2944 KB
random1_07.txt
WA
2 ms
2944 KB
random1_08.txt
WA
2 ms
2944 KB
random2_01.txt
WA
2 ms
2944 KB
random2_02.txt
WA
2 ms
2944 KB
random2_03.txt
WA
2 ms
2944 KB
random2_04.txt
WA
2 ms
2944 KB
random2_05.txt
WA
2 ms
2944 KB
random2_06.txt
WA
2 ms
2944 KB
random3_01.txt
WA
2 ms
2944 KB
random3_02.txt
WA
2 ms
2944 KB
random4_01.txt
WA
2 ms
2944 KB
random4_02.txt
WA
2 ms
2944 KB
random4_03.txt
WA
2 ms
2944 KB
sample_01.txt
WA
3 ms
2944 KB
sample_02.txt
WA
2 ms
2944 KB
sample_03.txt
WA
2 ms
2944 KB
star_01.txt
WA
2 ms
2944 KB
star_02.txt
WA
2 ms
2944 KB