Source stringclasses 1
value | Date int64 2.01k 2.02k | Text stringlengths 22 783k | Token_count int64 20 394k |
|---|---|---|---|
Project_CodeNet | 2,018 | #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 200005
const int INF=1000000;
int n,m,w[maxn],pre[maxn],other[maxn],last[maxn],o,l[maxn],r[maxn];
bool flag[maxn];
void connect(int x,int y)
{
o++;
pre[o]=last[x];
last[x]=o;
other[o]=y;
}
void dfs(int u,int fa)
{... | 493 |
Project_CodeNet | 2,019 | #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n, k;
const int maxn = 1e5 + 5;
int odd[maxn];
int a[maxn], b[maxn];
int p[maxn];
int lower[maxn], upper[maxn];
vector<int> G[maxn];
bool dfs(int u, int fa){
bool flag = true;
for(auto v :... | 960 |
Project_CodeNet | 2,018 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< "... | 697 |
Project_CodeNet | 2,020 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, K;
vector<pair<int, int>> v, vv;
vector<pair<int, int>> G[100010];
vector<int> d(100010, INT_MAX);
priority_queue<pair<int, int>> que;
int main () {
cin >> N;
for (int i = 0; i < N-1; i++) {
int A, B;
cin >> A >> B;
... | 422 |
Project_CodeNet | 2,019 | #include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
vector<int>G[100006];
int al[100006], au[100006];
int des[100006],dis[100006];
void dfs1(int now, int par) {
... | 664 |
Project_CodeNet | 2,019 | #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#in... | 1,006 |
Project_CodeNet | 2,020 | #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int>G[maxn];
int n, k, val[maxn], fa[maxn], now[maxn], dif[maxn];
inline void Add(int u, int v) {
int x = dif[v] + 1;
if(dif[u] < 1e7 && dif[v] < 1e7 && (abs(now[u] + dif[u]) % 2 != abs(now[v] + x) % 2))
exit(0 * puts("No"));
int l = max... | 488 |
Project_CodeNet | 2,019 | #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define int long long
const int INF = (1e18);
const int MOD = 1000000007;
signed main(){
// cin.tie(0);
// ios::sync_with_stdio(false);
bool flag = true;
int N, K;
vector<int> dis, in;
vector<v... | 605 |
Project_CodeNet | 2,016 | #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <uno... | 949 |
Project_CodeNet | 2,018 | #include <iostream>
#include <vector>
#include <utility>
#include <set>
#define inf 100000000
using namespace std;
typedef pair<int, int> P;
int N, K;
vector<int> G[100005];
int p[100005];
P val[100005];
int ans [100005];
bool check(int v, int prev, int r)
{
if(p[v] != -1 && p[v] % 2 != r) return false;
for(int i ... | 660 |
Project_CodeNet | 2,020 | #include<bits/stdc++.h>
using namespace std;
#define end puts("No"),exit(0)
const int maxn=1e5+10;
int hea[maxn],nxt[maxn<<1],to[maxn<<1],p[maxn],l[maxn],r[maxn],tot;
void add(int a,int b) {
nxt[++tot]=hea[a];
hea[a]=tot;
to[tot]=b;
}
void dfs(int x,int f,int d) {
if(~p[x])l[x]=r[x]=p[x];
else if(d)l[x]=-1e9+1,r[x... | 461 |
Project_CodeNet | 2,018 | #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x7FFFFFFF
using namespace std;
int n,m;
int minl[MAXN],maxl[MAXN],p[MAXN];
bool flag=1;
vector<int> a[MAXN];
bool check(int x,int y,int val){
if(y==INF)
return 1... | 704 |
Project_CodeNet | 2,018 | #include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
//1175114440
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s s... | 835 |
Project_CodeNet | 2,016 | #include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <nume... | 1,679 |
Project_CodeNet | 2,016 | #include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#define MAXN 111111
#define Inf 1000000000
using namespace std;
pair<int,int> range[MAXN+1];
vector<int> edges[MAXN+1];
vector<int> unset_edges[MAXN+1];
bool isset[MAXN+1];
bool change;
map<p... | 960 |
Project_CodeNet | 2,019 | #include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)... | 1,128 |
Project_CodeNet | 2,016 | #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <string>
#include <cmath>
#define SIZE 100005
#define INF 1000000000
using namespace std;
typedef long long int ll;
typedef pair ... | 603 |
Project_CodeNet | 2,020 | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author tatsumack
*/
#include <iostream>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstr... | 944 |
Project_CodeNet | 2,017 | #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
int w=0;bool q=1;char c=getcha... | 509 |
Project_CodeNet | 2,018 | #include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; ++ i)
#define pb push_back
#define fi first
#define se second
typedef pair < int, int > ii;
const int N = 1e5 + 5, INF = 1e8;
int n, k;
int res[N];
vector < int > adj[N];
priority_queue < ii > pq;
signed main(){
ios_base::sync... | 323 |
Project_CodeNet | 2,016 |
/* -------------------------------- Template -------------------------------- */
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <ios... | 956 |
Project_CodeNet | 2,020 | #include<bits/stdc++.h>
#define rint register int
#define ll long long
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
struct node{int to,next,v;} e[1010100];
int N,K,h[1010000],tot,A[1010000];
int Min[1010000],rt,dep[1000100],depp[1010000],vis[1001000];
inline void add(int from,int to) {
e[++tot].to=to;... | 665 |
Project_CodeNet | 2,016 | #include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int ans[100000];
int a[100000];
int b[100000];
vector <int> v[100000];
void dfs(int x, int y, int l, int r) {
int i;
if (ans[x] != 1e9) {
if (ans[x] < l || ans[x] > r || (r - ans[x]) % 2 == 1) {
... | 777 |
Project_CodeNet | 2,020 | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>... | 1,021 |
Project_CodeNet | 2,016 | #include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <functional>
#include <map>
namespace XX
{
template<template<typename> class Compare, typename T>
inline T& UP(T& x, const T& y){if(Compare<T>()(y, x)) x = y; return x;}
template<typename Compare, typename T>
inline T& ... | 1,759 |
Project_CodeNet | 2,020 | //header
#ifdef LOCAL
#include "cxx-prettyprint-master/prettyprint.hpp"
#define print(x) cout << x << endl
#else
#define print(...) 42
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//types
using namespace std;
using ll = long long;
typedef pair < ll , ll >Pl;
type... | 1,562 |
Project_CodeNet | 2,017 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
set <pair <int, int> > ms;
int a[MAXN];
vector <int> g[MAXN];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n-1; i++)
{
int u, v;
cin >> u >> v;
g[v].push_back(u);
g[u].push_back(v);
}
fo... | 371 |
Project_CodeNet | 2,016 | #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(in... | 675 |
Project_CodeNet | 2,016 | #include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pa... | 664 |
Project_CodeNet | 2,017 | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
using namespace std;
int N;
vector<int> edge[100001];
pair<int,int> range[100001];
bool used[100001];
int num[100001];
int lower = -1000000000;
int upper = 100000... | 542 |
Project_CodeNet | 2,016 | #include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
#define ll long long
#define ull unsigned ll
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<=... | 1,695 |
Project_CodeNet | 2,017 | #include <iostream>
#include <vector>
#define INF 1e+9
using namespace std;
int n,k,l[100000],r[100000],num[100000];
vector<int> G[100000];
bool flag = true;
void dfs(int v,int par){
int mi = -INF,ma = INF;
for(int to : G[v]){
if(to == par) continue;
dfs(to,v);
mi = max(mi,l[to]);
ma = min(ma,r[to]);
}
if... | 519 |
Project_CodeNet | 2,018 | #include"bits/stdc++.h"
using namespace std;
using ll = int64_t;
vector<vector<ll>> edges;
vector<ll> value;
vector<pair<ll, ll>> conds;
bool flag;
pair<ll, ll> solve(ll curr, ll pre) {
pair<ll, ll> cond{ INT_MIN, INT_MAX };
if (value[curr] != -1) {
cond.first = cond.second = value[curr];
}
fo... | 624 |
Project_CodeNet | 2,016 | #include <bits/stdc++.h>
using namespace std ;
int n, K ;
const int MAXN = 100010 ;
int a[MAXN] ;
struct Edge {
int l, r, nxt;
} e[MAXN << 1];
int ecnt = 0, hed[MAXN] ;
void addedge(int l, int r) {
++ecnt, e[ecnt].l = l, e[ecnt].r = r, e[ecnt].nxt = hed[l], hed[l] = ecnt ;
}
int root = 0 ;
int L[MAXN], ... | 784 |
Project_CodeNet | 2,018 | /*
ID:atcoder gbc1749940268
PROB:Integers on a tree
LANG:C++
*/
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _|... | 6,721 |
Project_CodeNet | 2,020 | #include<bits/stdc++.h>
using namespace std;
priority_queue<pair<int,int> >q;
const int N=100009;
int he[N],to[N<<1],ne[N<<1],g[N];
bool f[N];
int main(){
int n,i,j,k,t=0,m;
scanf("%d",&n);
for(i=1;i<n;++i){
scanf("%d%d",&j,&k);
ne[++t]=he[j],to[t]=k,he[j]=t;
ne[++t]=he[k],to[t]=j,he[k]=t;
}
scanf("%d",&k);
... | 287 |
Project_CodeNet | 2,017 | #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cs... | 1,222 |
Project_CodeNet | 2,018 | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9;
int n, minv[100005], maxv[100005], color[100005];
vector<int> G[100005];
void dfs1(int x, int px, int dep){
color[x] = dep % 2;
for(int nx : G[x]){
if( nx == px ) continue;
dfs1( nx, x, dep + 1 );
... | 907 |
Project_CodeNet | 2,020 | #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// usi... | 1,317 |
Project_CodeNet | 2,020 | #include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#... | 899 |
Project_CodeNet | 2,020 | parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
n = readline() |> parseInt
e = [Int[] for i in 1:n]
for i in 1:n-1
a,b = readline() |> split |> parseMap
push!(e[a],b)
push!(e[b],a)
end
k = readline() |> parseInt
num = Tuple{Int,Int}[(-10^18,10^18) for ... | 607 |
Project_CodeNet | 2,020 | import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
fun PrintWriter.solve(sc: FastScanner) {
val n = sc.nextInt()
val adj = Array(n) { mutableSetOf<Int>() }
for (i in 0 until n - 1) {
val v1 = sc.nextInt() - 1
... | 1,028 |
Project_CodeNet | 2,020 | macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s... | 1,757 |
Project_CodeNet | 2,017 | #![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;
trait InputValue {
fn parse(s: &str) -> Self;
}
fn read<T: InputValue>() -> T {
let mut buf = String::new();
let _ = stdin().read_line(&mut buf);
T::parse(... | 713 |
Project_CodeNet | 2,020 | #![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
#[allow(unused_macros)]
macro_rules! debug {
($($e:expr),*) => {
#[cfg(debug_assertions)]
$({
let (e, mut err) = (stringify!($e), std::io::stderr());
writeln!(er... | 1,015 |
Project_CodeNet | 2,020 | // ---------- begin Rerooting ----------
struct Rerooting<Edge, Value, Func, Init> {
size: usize,
edge: Vec<(usize, usize, Edge, Edge)>,
init: Init,
merge: Func,
phantom: std::marker::PhantomData<Value>,
}
impl<Edge, Value, Func, Init> Rerooting<Edge, Value, Func, Init>
where
Edge: Clone,
V... | 1,714 |
Project_CodeNet | 2,020 |
use std::{cmp::{max, min}, collections::{BTreeMap, BTreeSet, VecDeque}};
fn read_line() -> String {
let mut buffer = String::new();
std::io::stdin().read_line(&mut buffer).expect("No Line");
buffer
}
fn read_lines<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
let mut buffer = String::n... | 1,459 |
Project_CodeNet | 2,019 | macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
let mut next = || { iter.next().unwrap() };
input_inner!{next, $($r)*}
};
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufRead... | 1,179 |
Project_CodeNet | 2,020 | use std::collections::VecDeque;
fn main() {
let (r, w) = (std::io::stdin(), std::io::stdout());
let mut sc = IO::new(r.lock(), w.lock());
let n: usize = sc.read();
let mut graph = vec![vec![]; n];
for _ in 1..n {
let a = sc.read::<usize>() - 1;
let b = sc.read::<usize>() - 1;
... | 932 |
Project_CodeNet | 2,020 | #![allow(unused_imports, unused_macros)]
use kyoproio::*;
use std::{
collections::*,
io::{self, prelude::*},
iter,
mem::{replace, swap},
};
fn main() -> io::Result<()> {
std::thread::Builder::new()
.stack_size(64 * 1024 * 1024)
.spawn(|| {
let stdin = io::stdin();
... | 1,708 |
Project_CodeNet | 2,019 | #![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]
fn main() {
let N: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let (A, B): (Vec<usize>, Vec<usize>) = {
let (mut A, ... | 1,164 |
Project_CodeNet | 2,019 | package main
import (
"bufio"
"container/heap"
"fmt"
"os"
"strconv"
"strings"
)
const INF = 1000000000
func main() {
input := Input{bufio.NewReaderSize(os.Stdin,100)}
n := input.NextInt()
g := make([][]int,n)
for i:=0;i<n-1;i++ {
a,b := input.NextInts()
g[a-1] = append(g[a-1],b-1)
g[b... | 1,041 |
Project_CodeNet | 2,019 | package main
import (
"bufio"
"os"
"strconv"
"strings"
"fmt"
"sort"
)
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
var line, buffer []byte
var isPrefix bool = true
var err error
for isPrefix {
line, isPrefix, err = reade... | 1,181 |
Project_CodeNet | 2,018 | //set many funcs template
//Ver.20180717
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){i... | 1,245 |
Project_CodeNet | 2,019 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const vo... | 1,193 |
Project_CodeNet | 2,020 | #include <stdio.h>
typedef struct List {
struct List *next;
int v;
} list;
int main()
{
const int sup = 1 << 30, inf = -sup;
int i, N, K, u, w, l[100001], r[100001];
list *adj[100001] = {}, e[200001];
scanf("%d", &N);
for (i = 0; i < N - 1; i++) {
scanf("%d %d", &u, &w);
e[i*2].v = w;
e[i*2+1].v = u;
e... | 731 |
Project_CodeNet | 2,018 | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
typedef struct naiveVector{
void *array;
size_t size;
int maxLen;
int len;
} vector;
void push_back(vector *vec,const void *v){
if(vec->len==vec->maxLen){
vec->maxLen=vec->maxLe... | 811 |
Project_CodeNet | 2,016 | #include<stdio.h>
#include<stdlib.h>
long long CO[100010];
long long R=1,C=1,H[2000010],N[2000010];
//評価関数(いまはMAX)
long long hyouka(long long a,long long b){
if(C<b)return 1;
if(C<a||b==0)return 0;
return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
long long i=C++;
for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)... | 861 |
Project_CodeNet | 2,020 | local mmi, mma = math.min, math.max
local n = io.read("*n")
local edge = {}
local len = {}
local parent = {}
local childcnt = {}
local valmin, valmax = {}, {}
for i = 1, n do
edge[i] = {}
len[i] = -1
parent[i] = 0
childcnt[i] = 0
valmin[i], valmax[i] = false, false
end
for i = 1, n - 1 do
local a, b = io.re... | 852 |
Project_CodeNet | 2,019 | import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
alias P = Tuple!(long, "min", long, "max", bool, "odd", bool, "init");
void main()
{
auto N = readln.chomp.to!int;
int[][] T;
T.length = N;
foreach (_; 0..N-1) {
auto ab = readln.split.to!(in... | 741 |
Project_CodeNet | 2,016 | import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
//import std.math;
import std.container;
import std.numeric;
import std.bigint;
import core.stdc.stdlib;
alias Tuple!(int, "lower", int, "upper") bound;
int N, K;
int... | 725 |
Project_CodeNet | 2,016 | module e;
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
class Node{
int id;
Node[] adjnodes;
int x;
int _value;
bool hasValue = false;
int color = 0; // 0: undef, 1: black, 2: white
int min = 0, max = 1_000_000;
... | 781 |
Project_CodeNet | 2,018 | import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
auto g = Graph... | 1,193 |
Project_CodeNet | 2,019 | import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int, input().split())
E[a].append(b)
E[b].append(a)
K = int(input())
L = [-float("inf")] * (N+1)
R = [float("inf")] * (N+1)
for _ in range(K):
v, p = map(int, input().split())
L[v]... | 392 |
Project_CodeNet | 2,020 | import sys
sys.setrecursionlimit(10 ** 7)
def dfs(v, parent, odd):
hi = INF
lo = -INF
if fixed[v] != INF:
if odd_even[v] != odd:
print('No')
exit()
hi = lo = fixed[v]
for u in links[v]:
if u == parent:
continue
chi, clo = dfs(u, v, o... | 478 |
Project_CodeNet | 2,019 | #設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
import queue
INF = float("inf")
#入力受け取り
def getlist():
return list(map(int, input().split()))
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return le... | 862 |
Project_CodeNet | 2,016 | from heapq import heappush, heappop
def checker():
N=int(raw_input())
edge=[[] for _ in xrange(N)]
for _ in xrange(N-1):
a,b=map(int,raw_input().split())
edge[a-1]+=[b-1]
edge[b-1]+=[a-1]
P=[None]*N
d=[False]*N
q=[]
K=int(raw_input())
for _ in xrange(K):
v,p=map(int,raw_input().split())... | 272 |
Project_CodeNet | 2,020 | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]
K = int(sys.std... | 553 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
A, B = map(int, input().split())
G[A].append(B)
G[B].append(A)
K = int(input())
num = [-1] * (N+1)
for _ in range(K):
V, P = map(int, input().split())
num[V] = P
# ... | 544 |
Project_CodeNet | 2,020 | def main():
n = int(input())
ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
k = int(input())
vp = [list(map(int, input().split())) for _ in [0]*k]
g = [[] for _ in [0]*n]
[g[a-1].append(b-1) for a, b in ab]
[g[b-1].append(a-1) for a, b in ab]
# まず各頂点の偶奇を計算する
parity = [-1... | 700 |
Project_CodeNet | 2,020 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
x, y = map(int, input().split())
X[x-1].append(y-1)
X[y-1].append(x-1)
Y = [(-10**9, 10**9) for _ in range(N)]
K = int(input())
for _ in range(K):
v, ... | 456 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
NUM = [-1]*N
K = int(input())
for _ in range(K):
a, b = map(int, input().split())
N... | 480 |
Project_CodeNet | 2,019 | import sys
readline = sys.stdin.readline
def getpar(Edge, p):
N = len(Edge)
par = [0]*N
par[0] = -1
par[p] -1
stack = [p]
visited = set([p])
while stack:
vn = stack.pop()
for vf in Edge[vn]:
if vf in visited:
continue
visited.add(v... | 722 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+100)
from collections import *
def dfs(v, pv, de):
for nv in G[v]:
if nv==pv:
continue
dfs(nv, v, de+1)
left[v] = max(left[v], left[nv]-1)
right[v] = min(right[v], right[nv]+1)
if v in d:... | 388 |
Project_CodeNet | 2,019 | from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
adj = [[] for _ in range(N + 1)]
for _ in range(N-1):
A, B = map(int, input().split())
adj[A].append(B)
adj[B].append(A)
K = int(input())
ans = [[-10 ** 10 + 0.5, 10 ** 10 + 0.5] for _ in range(N + 1)]
for _ in range(K):
... | 446 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.readline
N = int(input())
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
u, v = map(int, input().split())
e[u].append(v)
e[v].append(u)
s = [1]
color = [0] * (N + 1)
color[1] = 1
while len(s):
x = s.pop()
for y in e[x]:
if color[y]:
if color[x] == color[y]: break... | 373 |
Project_CodeNet | 2,020 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, co... | 681 |
Project_CodeNet | 2,020 | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, = map(int,readline().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
a,b = map(int,readline().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
order = []
parent = [-1]*n
st = [0]
while st:
... | 479 |
Project_CodeNet | 2,020 | import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
N=int(input())
edge={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
a,b=map(int,input().split())
edge[a].append(b)
edge[b].append(a)
K=int(input())
dic={}
for i in range(K):
v,p=map(int,input().split())
dic[v]=0
dic[v]=p
... | 600 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
T[a].append(b)
T[b].append(a)
k = int(input())
VP = tuple(tuple(map(int, input().split())) for _ in range(k))
P = [-1]*(n+1)
A = [-1]... | 416 |
Project_CodeNet | 2,019 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
K = int(input())
v_to_p = [None] * (N+1)
for _ in range(K):
v,p = map(int,input().split())
... | 557 |
Project_CodeNet | 2,016 | from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
def inc(x):
if x == "No":
return "No"
elif x == "Any":
retur... | 666 |
Project_CodeNet | 2,020 |
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc063/tasks/arc063_c
数字が置かれている頂点は範囲指定の制約になる
→制約をすべての点に伝播させれば、後はその範囲内から適当に選んで実装すればよい
一度根方向に制約を集め、それを全方位に伝播させればよい?
→それっぽさそう
偶奇に関してはちゃんと考えてね
→条件の両端の偶奇で判断可能
"""
import sys
sys.setrecursionlimit(5*10**5)
N = int(input())
lis = [ [] for i in range(N) ]
for i in range(N... | 669 |
Project_CodeNet | 2,016 | from sys import stdin, stdout
from heapq import heappush, heappop
def main():
RL = stdin.readline
n = int(RL())
e = [[] for _ in xrange(n)]
for _ in xrange(n - 1):
x, y = map(int, RL().split())
x -= 1
y -= 1
e[x] += [y]
e[y] += [x]
m = int(RL())
f = [None]... | 322 |
Project_CodeNet | 2,016 | from heapq import*
R=range;I=lambda:map(int,input().split());n=int(input());g=[[]for _ in R(n+1)];z=[-1]*n;d=[1e9]*n+[0];q=[-1]*(n+1);r='';Q=[];heappush(Q,(0,-2,n))
for _ in R(n-1):a,b=I();a-=1;b-=1;g[a]+=[(1,a,b)];g[b]+=[(1,b,a)]
for _ in R(*I()):a,b=I();a-=1;g[n]+=[(b,n,a)];z[a]=b
while Q:
e=heappop(Q)
if q[e[2]]!=... | 305 |
Project_CodeNet | 2,020 | def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
edge=[[] for i in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
edge[a].append(b)
edge[b].append(a)
INF=floa... | 362 |
Project_CodeNet | 2,019 | import sys
sys.setrecursionlimit(10**6)
n = int(input())
tr = [list() for _ in range(n)]
num = [None]*n
ran = [0]*n
dep = [0]*n
for _ in range(n-1):
a,b = map(int,input().split())
a -= 1; b -= 1
tr[a].append(b)
tr[b].append(a)
k = int(input())
root,c = map(int,input().split())
root -= 1
num[root] = c
def dfs(... | 520 |
Project_CodeNet | 2,020 | import sys
sys.setrecursionlimit(10**6)
INF = 10**7
def input():
return sys.stdin.buffer.readline()[:-1]
n = int(input())
ver = [[-INF, INF] for _ in range(n)]
adj = [[] for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
k = int(input())
for _ in ran... | 470 |
Project_CodeNet | 2,018 | import sys
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
A, B = map(int, input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
M = {}
K = int(input())
for i in range(K):
V, P = map(int, input().split())
M[V-1] = P
memo = [0]*N
def dfs(v, p, x, y):
... | 453 |
Project_CodeNet | 2,019 | import sys
sys.setrecursionlimit(10**6)
INF = 10**7
n = int(input())
edge = [[] for _ in range(n)]
for i in range(n - 1):
u, v = [int(item) - 1 for item in input().split()]
edge[u].append(v)
edge[v].append(u)
k = int(input())
number = [-INF] * n
for i in range(k):
v, c = [int(item) for item in input().s... | 610 |
Project_CodeNet | 2,020 | class Tree():
def __init__(self, n, edge, indexed=1):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - indexed].append(e[1] - indexed)
self.tree[e[1] - indexed].append(e[0] - indexed)
def setroot(self, root):
self.root = root
... | 712 |
Project_CodeNet | 2,019 | from collections import deque
import sys
sys.setrecursionlimit(int(1e7))
def inpl(): return list(map(int, input().split()))
N = int(input())
G = [[] for _ in range(N+1)]
X = [-1 for _ in range(N+1)] # is odd
U = [1e7 for _ in range(N+1)]
L = [-1e7 for _ in range(N+1)]
for _ in range(N-1):
a, b = inpl()
G[a]... | 524 |
Project_CodeNet | 2,020 | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
K = int(input())
res = [-1]*N
for i in range(K):
v, p = map(int, ... | 515 |
Project_CodeNet | 2,016 | import sys
import heapq
o=lambda:map(int,raw_input().split());r=range
n=int(raw_input())
e=[[] for _ in r(n+1)]
for _ in r(n-1):a,b=o();e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in r(k):v,p=o();e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*(n+1)
cst=[10**9]*(n+1)
q=[(0,0)]
heapq.heapify(q)
while len(q):
c,v=he... | 255 |
Project_CodeNet | 2,020 | import heapq
import sys
input = sys.stdin.readline
INF = 10 ** 18
n = int(input())
edges = [list(map(int, input().split())) for i in range(n - 1)]
k = int(input())
info = [list(map(int, input().split())) for i in range(k)]
tree = [[] for i in range(n)]
for a, b in edges:
a -= 1
b -= 1
tree[a].append(b)
... | 299 |
Project_CodeNet | 2,020 | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().spli... | 585 |
Project_CodeNet | 2,018 | class Heap
attr_reader :size
def initialize
@heap = []
@size = 0
end
def length
@size
end
def push(x)
i = @size
@size += 1
while i > 0
p = (i - 1) / 2
break if @heap[p] <= x
@heap[i] = @heap[p]
i = ... | 482 |
Project_CodeNet | 2,019 | N = gets.to_i
es = {}
(N-1).times{
a,b = gets.split.map &:to_i
es[a] ||= {}; es[b] ||= {}
es[a][b] = es[b][a] = 1
}
ranges = Array.new(N+1,nil)
parities = Array.new(N+1,nil)
K = gets.to_i
K.times {
v,q = gets.split.map &:to_i
ranges[v] = [q,q]
parities[v] = q%2
}
queue = [[1,0]]
while queue.size > 0 do
n... | 543 |
Project_CodeNet | 2,018 | using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
var E = new List<int>[N];
for(int i=0;i<N;i++) E[i] = new List<int>();
for(int i=0;i<... | 1,188 |
Project_CodeNet | 2,016 | using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using static Func;
class E { static void Main() => new J(); }
class J
{
int F => int.Parse(Console.ReadLine());
int[] G => Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
HashSet<int>[] es;
... | 754 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.