Submission #1694549
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
int N, E[150000][2];
vi G[150000];
float dp[150001][2];
float f(int e, int s) {
float &res = dp[e][s];
if (res > -1)return res;
int u = E[e][s];
res = 0;
if (sz(G[u]) == 1)return res;
float p = 1.0 / (sz(G[u]) - 1);
each(ne, G[u])if (ne != e) {
res += f(ne, E[ne][0] == u);
}
res = res*p + 1.0;
return res;
}
int main(){
scanf("%d", &N);
rep(i, N-1) {
int u, v;
scanf("%d%d", &u, &v);
--u; --v;
E[i][0] = u;
E[i][1] = v;
G[u].push_back(i);
G[v].push_back(i);
}
rep(i, N)rep(j, 2)dp[i][j] = -2;
rep(i, N) {
float ans = 0, p = -1;
if (sz(G[i]))p = 1.0 / sz(G[i]);
each(e, G[i]) {
ans += f(e, E[e][0] == i);
}
if (sz(G[i]))ans = ans*p + 1;
printf("%.8f\n", ans);
}
}
Submission Info
Submission Time |
|
Task |
D - Driving on a Tree |
User |
paruki |
Language |
C++14 (GCC 5.4.1) |
Score |
410 |
Code Size |
1470 Byte |
Status |
WA |
Exec Time |
1056 ms |
Memory |
18304 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:40:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
./Main.cpp:43:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &v);
^
Judge Result
Set Name |
Subtask1 |
Subtask2 |
Subtask3 |
Score / Max Score |
190 / 190 |
220 / 220 |
0 / 390 |
Status |
|
|
|
Set Name |
Test Cases |
Subtask1 |
sub1_in1.txt, sub1_in2.txt, sub1_in3.txt |
Subtask2 |
sub2_in1.txt, sub2_in2.txt |
Subtask3 |
sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub2_in1.txt, sub2_in2.txt, sub3_in1.txt, sub3_in2.txt, sub3_in3.txt |
Case Name |
Status |
Exec Time |
Memory |
sub1_in1.txt |
AC |
3 ms |
3712 KB |
sub1_in2.txt |
AC |
3 ms |
3840 KB |
sub1_in3.txt |
AC |
126 ms |
15744 KB |
sub2_in1.txt |
AC |
3 ms |
3840 KB |
sub2_in2.txt |
AC |
3 ms |
3840 KB |
sub3_in1.txt |
WA |
132 ms |
12544 KB |
sub3_in2.txt |
TLE |
1056 ms |
11380 KB |
sub3_in3.txt |
AC |
93 ms |
18304 KB |