Skip to content

Instantly share code, notes, and snippets.

#include <cstdio>
#include <vector>
using namespace std;
vector<int> v;
int n,adj[1005][1005];
void f(int x){
for (int i=1; i<=n; i++) {
if(adj[x][i]){
int dfs(int x, int p){
vector<int> e;
for(auto &i : tr[x]){
if(i == p) continue;
e.push_back(dfs(i, x));
}
if(e.empty()) return 1;
sort(e.begin(), e.end());
for(int i=0; i<e.size()-1; i++){
v.push_back(e[i]);
const int MAXN = 100005, MAXC = 26;
struct aho_corasick{
int trie[MAXN][MAXC], piv; // trie
int fail[MAXN]; // failure link
int term[MAXN]; // output check
void init(vector<string> &v){
memset(trie, 0, sizeof(trie));
memset(fail, 0, sizeof(fail));
memset(term, 0, sizeof(term));
@koosaga
koosaga / fb17r3a.cpp
Created January 29, 2017 15:35
FBHC17 R3 Solution
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
int rev[1005], sfx[1005];
char str[1005];
int n;
@koosaga
koosaga / b.cpp
Last active September 16, 2017 08:44
ACM-ICPC Daejeon Regional 2016
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
int cnt[10005], n;
int main(){
cin >> n;
int sum = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
struct disj{
int pa[2000005];
void init(int n){
for(int i=0; i<=n; i++) pa[i] = i;
}
@koosaga
koosaga / fft.cpp
Last active August 1, 2021 06:12
typedef long long lint;
namespace fft{
typedef complex<double> base;
void fft(vector<base> &v, bool inv){
vector<base> w(v.size());
for(int i=2; i<=v.size(); i<<=1){
int bsz = v.size() / i;
base ang(cos(2 * M_PI / i), sin(2 * M_PI / i));
if(inv) ang = base(1, 0) / ang;
@koosaga
koosaga / qtree.cpp
Created November 2, 2016 10:34
qtree.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
struct seg{
int tree[270000], lim;
void init(int n){
for(lim = 1; lim <= n; lim <<= 1);
}
void add(int x, int v){
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
int n;
lint basis[60];
int main(){
struct sfxarray{
int ord[MAXN], nord[MAXN], cnt[MAXN], aux[MAXN];
void solve(int n, char *str, int *sfx, int *rev){
int p = 1;
memset(ord, 0, sizeof(ord));
for(int i=0; i<n; i++){
sfx[i] = i;
ord[i] = str[i];
}
int pnt = 1;