https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-422-Div-2-problem-F-Madness-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #422 (Div. 2), problem: (F) Madness Solution In C/C++

#include<cstdio>
#include<cstdlib>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define pi acos(-1.0)
typedef long long ll;
typedef double db;
const int MAXN = 105;
vector<pair<int, int> >e[MAXN];
int fa[MAXN], id[MAXN];
db t[MAXN];

void dfs(int u){
db now=t[u], add=2.0/e[u].size();
for(int i=0; i<(int)e[u].size(); i++){
int v=e[u][i].first;
if(v==fa[u]) continue;
fa[v]=u, id[v]=e[u][i].second;
t[v]=fmod((now+=add)+1.0, 2.0);
dfs(v);
}
}
int main(){
int n;
scanf(“%d”, &n);
for(int i=1; i<=n-1; i++){
int u, v;
scanf(“%d %d”, &u, &v);
e[u].push_back(make_pair(v, i));
e[v].push_back(make_pair(u, i));
}
dfs(1);
printf(“%d\n”, n-1);
for(int i=2; i<=n; i++){
printf(“%d %d “, 1, id[i]);
if(t[i]<1) printf(“%d %d %.12f\n”, i, fa[i], t[i]);
else printf(“%d %d %.12f\n”, fa[i], i, t[i]-1);
}
return 0;
}

(Visited 22 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: