description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class C {
static InputStream is;
//String INPUT = "";
public static void main(String[] args) throws Exception {
is = System.in;
int n = ni();
ArrayList<Integer>[] aj = new ArrayList[n+1];
for (int i = 0; i < aj.length; ... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
long double ans = 0;
void dfs(int at, int par, long double h = 0, long double p = 1) {
for (__typeof(v[at].begin()) it = v[at].begin(); it != v[at].end(); it++) {
int to = *it;
if (to != par) {
long double p1 = v[at].size();
if (... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
int n;
long double ans;
vector<int> g[100005];
void dfs(int v, int p, int l, long double f) {
if ((int)g[v].size() == 1 && g[v][0] == p) {
ans += (long double)l * f;
return;
}
int k = (int)g[v].size();
if (v != 1) --k;
for (int i = 0; i < (int)g[v].size();... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.util.*;
public class Main {
@SuppressWarnings("unchecked")
static LinkedList<Integer>[] G = new LinkedList[(int)(1e5+10)];
static double dfs (int u,int p){
double sum = 0;
for(int i: G[u]){
if(i != p){
sum += (1+dfs(i,u));
}
}
if(sum == 0){
return 0;
}
return (p==0)?(sum/(dou... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Yuan Lei
*/
public class Main {
public sta... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class CF_428_DIV2_C {
private static ArrayList<Integer>[] adjList;
private static boolean[] visited;
private static double dfs(int u) {
if (adjList[u].size() == 0) return 0.0;
if ... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | # Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
from collections import deque
def main():
n=int(input())
tree=[[] for _ in range(n+1)]
for _ in range(n-1):
x,y=map(int,input().split())
tree[x].append(y)
tree[y].append... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import sys;readline = sys.stdin.readline
def i1(): return int(readline())
def nl(): return [int(s) for s in readline().split()]
def nn(n): return [int(readline()) for i in range(n)]
def nnp(n,x): return [int(readline())+x for i in range(n)]
def nmp(n,x): return (int(readline())+x for i in range(n))
def nlp(x): return [... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import sys;readline = sys.stdin.readline
def i1(): return int(readline())
def nl(): return [int(s) for s in readline().split()]
def nn(n): return [int(readline()) for i in range(n)]
def nnp(n,x): return [int(readline())+x for i in range(n)]
def nmp(n,x): return (int(readline())+x for i in range(n))
def nlp(x): return [... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
int n, i, a, b;
vector<int> adj[100005];
long double res = 0, sol[100004] = {};
long long int len = 0;
long double prop[100005];
void goo(int ind, int fat) {
if (adj[ind].size() == 1 - (fat == -1)) {
sol[len] += prop[ind];
return;
}
for (int u = 0; u < adj[ind... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import sys
def r():
return list(map(int, input().split()))
n = int(input())
edge = [r() for i in range(n-1)]
adj = [[] for i in range(n+1)]
for e in edge:
adj[e[0]].append(e[1])
adj[e[1]].append(e[0])
prob = [0.0 for i in range(n+1)]
d = [0 for i in range(n+1)]
visited = [False for i in range(n+1)]
pro... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
using li = long long;
using ld = long double;
using pii = pair<int, int>;
istream& operator>>(istream& cin, vector<int>& a) {
for (int i = 0; i < a.size(); i++) cin >> a[i];
return cin;
}
ostream& operator<<(ostream& cout, vector<int>& a) {
for (int i = 0; i < a.size(... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import sys
from collections import deque
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
N = readi()
if N == 1:
writeln(0)
exit()
G = [set() for _ in range(N)]
for _ in range(N-1):
u, v = map(... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import sys;readline = sys.stdin.readline
def i1(): return int(readline())
def nl(): return [int(s) for s in readline().split()]
def nn(n): return [int(readline()) for i in range(n)]
def nnp(n,x): return [int(readline())+x for i in range(n)]
def nmp(n,x): return (int(readline())+x for i in range(n))
def nlp(x): return [... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
public class templ implements Runnable {
class pair
{
int first,second;
pair(int f,int s)
{
first=f;
second=s;
}
}
public static ArrayList<Integer> g[]=new ArrayLis... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
int n, vis[maxn];
vector<int> adj[maxn];
double dfs(int v, int p) {
vis[v] = 1;
double ans = 0, num = 0;
for (int u : adj[v]) {
if (u != p) {
ans += dfs(u, v);
num += 1;
}
}
return num ? ans / num + 1 : 0.0;
}
int main... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.util.*;
public class CF839C
{
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Point[] cities = new Point[n+1];
for(int i=1;i<=n;i++)
cities[i] = new Point(i);
for(int i=0;i<n-1;i++)
{
int a = sc.ne... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | import java.io.*;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import javax.management.relation.RelationServiceNotRegisteredException;
public class hehehe {
static int count=0;
static int... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O0")
#pragma GCC optimize("O1")
long long pw(int a, int b) {
long long ret = 1;
long long mul = a;
while (b > 0) {
if (b & 1) ret *= mul;
mul *= mul;
b /= 2;
}
ret... |
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | """
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout
def main():
n = int(stdin.readline().strip())
g = [[] for i in range(n+1)]
for _ in range(n-1):
u, v = [int(_) for _ in stdin.readline().strip().split()]
g[u].append(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.