Submission #1694603


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], deg[150000];
vi G[150000];
double dp[150001][2];

double f(int e, int s) {
    double &res = dp[e][s];
    if (res > -1)return res;
    int u = E[e][s];
    res = 0;
    if (sz(G[u]) == 1)return res;
    double 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(){
    int isLine = 1;
    scanf("%d", &N);
    rep(i, N-1) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        deg[u]++;
        deg[v]++;
        E[i][0] = u;
        E[i][1] = v;
    }

    rep(i, N)if (deg[i] > 2)isLine = 0;
    if (isLine) {
        double ans = 0.5*(N - 1);
        rep(i, N) {
            if(deg[i]==2)printf("%.10f\n", ans);
            else printf("%d\n", N - 1);
        }
        exit(0);
    }
    assert(0);
    rep(i, N - 1)rep(j, 2)G[E[i][j]].push_back(i);
    rep(i, N)rep(j, 2)dp[i][j] = -2;
    rep(i, N) {
        double 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("%.10f\n", ans);
    }
}

Submission Info

Submission Time
Task D - Driving on a Tree
User paruki
Language C++14 (GCC 5.4.1)
Score 190
Code Size 1803 Byte
Status RE
Exec Time 125 ms
Memory 6912 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
./Main.cpp:44: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 0 / 220 0 / 390
Status
AC × 3
RE × 2
AC × 3
RE × 5
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 2 ms 4352 KB
sub1_in2.txt AC 3 ms 4352 KB
sub1_in3.txt AC 82 ms 6912 KB
sub2_in1.txt RE 99 ms 4352 KB
sub2_in2.txt RE 99 ms 4352 KB
sub3_in1.txt RE 125 ms 5888 KB
sub3_in2.txt RE 121 ms 5888 KB
sub3_in3.txt RE 125 ms 5888 KB