buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <stdio.h> #define MAX 100 #define WHITE 0 #define GRAY 1 #define BLACK 2 int n; int M[MAX][MAX] = {0}; int color[MAX] = {0}, d[MAX] = {0}, f[MAX] = {0}, tt; void dfs_visit(int u) { int v; color[u] = GRAY; d[u] = ++tt; for (v = 0; v < n; v++) { if (M[u][v] == 0) continue; if (color[v] =...
#include <stdio.h> #define MAX 100 #define WHITE 0 #define GRAY 1 #define BLACK 2 int n; int M[MAX][MAX] = {0}; int color[MAX] = {0}, d[MAX] = {0}, f[MAX] = {0}, tt; void dfs_visit(int u) { int v; color[u] = GRAY; d[u] = ++tt; // printf("u = %d d[u] = %d\n", u + 1, d[u]); for (v = 0; v < n; v++) { if (...
[["-", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["-", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16...
0
328
10
#include <stdio.h> #define N 101 int M[N][N] = {}; int d[N]; int f[N]; char color[N]; int n; int time; void visit(int u) { int i; color[u] = 'G'; d[u] = ++time; for (i = 1; i <= n; i++) { if (M[u][i] == 1 && color[i] == 'W') { visit(i); } } color[u] = 'B'; f[u] = ++time; } void dfs() { ...
#include <stdio.h> #define N 101 int M[N][N] = {}; int d[N]; int f[N]; char color[N]; int n; int time; void visit(int u) { int i; color[u] = 'G'; d[u] = ++time; for (i = 1; i <= n; i++) { if (M[u][i] == 1 && color[i] == 'W') { visit(i); } } color[u] = 'B'; f[u] = ++time; } void dfs() { ...
[["-", 8, 57, 15, 23, 0, 16, 31, 69, 71, 22], ["+", 8, 57, 15, 23, 0, 16, 31, 69, 71, 22]]
0
326
2
#include <stdio.h> #define N 100 int i, j, n, d[N], f[N], v, color[N], time, G[N][N] = {}; void visit(int u) { color[u] = 1; d[u] = ++time; for (v = 0; v < n; v++) { if (G[u][v] != 0) { if (color[v] == 0) { visit(v); } } } color[u] = 2; f[u] = ++time; } void dfs() { for (i...
#include <stdio.h> #define N 100 int i, j, n, d[N], f[N], color[N], time, G[N][N] = {}; void visit(int u) { int v; color[u] = 1; d[u] = ++time; for (v = 0; v < n; v++) { if (G[u][v] != 0) { if (color[v] == 0) { visit(v); } } } color[u] = 2; f[u] = ++time; } void dfs() { ...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 49, 22], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35]]
0
322
5
#include <stdio.h> #define N 100 #define X 0 #define Y 1 #define Z 2 int n, t; int M[N][N]; int c[N], d[N], f[N]; void dfs1(int); void dfs(void); int main() { int u, v; int i, j, k; scanf("%d%d", &u, &k); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { M[i][j] = 0; } } for (i = 0; i <...
#include <stdio.h> #define N 100 #define X 0 #define Y 1 #define Z 2 int n, t; int M[N][N]; int c[N], d[N], f[N]; void dfs1(int); void dfs(void); int main() { int u, v; int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { M[i][j] = 0; } } for (i = 0; i < n; i+...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22]]
0
389
7
#include <stdio.h> #define MAX 100 void DepthFirstSearch(); void roop(int); int d[MAX], f[MAX], arr2[MAX]; int N, time; #define MAX 100 #define IN -1 int a[MAX][MAX]; int main() { int i, j, count, num, arr; scanf("%d", &N); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { a[i][j] = 0; } d...
#include <stdio.h> #define MAX 100 void DepthFirstSearch(); void roop(int); int d[MAX], f[MAX], arr2[MAX]; int N, time; #define MAX 100 #define IN -1 int a[MAX][MAX]; int main() { int i, j, count, num, arr; scanf("%d", &N); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { a[i][j] = 0; } d[...
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 7, 8, 9, 0, 57, 15, 23, 0, 25], ["+", 0, 7, 8, 9, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 9, 0, 57, 64, 116, 0, 35], ["+", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["+", 0, 7, 8, 9, 0, 57, 15, 23, 0, 24]]
0
377
6
#include <stdio.h> #include <stdlib.h> #define WHITE 0 #define GRAY 1 #define BLACK 2; void DFS(void); void visit(int); int n, **M, *color, *d, *f, time = 0; int main() { int i, j, u, k, v; scanf("%d", &n); M = (int **)malloc(sizeof(int *) * n); // dynamic allocation start for (i = 0; i < n + 1; i++) { ...
#include <stdio.h> #include <stdlib.h> #define WHITE 0 #define GRAY 1 #define BLACK 2; void DFS(void); void visit(int); int n, **M, *color, *d, *f, time = 0; int main() { int i, j, u, k, v; scanf("%d", &n); M = (int **)malloc(sizeof(int *) * n); // dynamic allocation start for (i = 0; i < n + 1; i++) { ...
[["-", 8, 9, 0, 1, 0, 11, 12, 27, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 27, 28, 22]]
0
475
4
#include <algorithm> #include <iostream> #include <string> using namespace std; string X, Y; int v[1001][1001]; int dp(string X, string Y) { int n = X.size(); int m = Y.size(); for (int i = 0; i < n; i++) { v[i][0] = 0; ///0のテーブル for (int j = 0; j < m; j++) { v[0][j] = 0; } } for (int i ...
#include <algorithm> #include <iostream> #include <string> using namespace std; string X, Y; int v[1001][1001]; int dp(string X, string Y) { int n = X.size(); int m = Y.size(); for (int i = 0; i <= n; i++) { v[i][0] = 0; ///0のテーブル for (int j = 0; j <= m; j++) { v[0][j] = 0; } } for (int ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51,...
1
269
8
#include <iostream> #include <string> #include <vector> using namespace std; void input(string &x, string &y) { cin >> x >> y; } int lcs(string x, string y) { vector<vector<int>> tb( vector<vector<int>>((int)x.size() + 1, vector<int>(y.size() + 1, 0))); for (int i = 1; i < (int)x.size() + 1; i++) { for (i...
#include <iostream> #include <string> #include <vector> using namespace std; void input(string &x, string &y) { cin >> x >> y; } int lcs(string x, string y) { vector<vector<int>> tb( vector<vector<int>>((int)x.size() + 1, vector<int>(y.size() + 1, 0))); for (int i = 1; i < (int)x.size() + 1; i++) { for (i...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
280
4
#include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1] = {}; int m = X.length(); int n = Y.length(); X = ' ' + X; Y = ' ' + Y; int maxl = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j < n; j++) { if (X[i] ...
#include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1] = {}; int m = X.length(); int n = Y.length(); X = ' ' + X; Y = ' ' + Y; int maxl = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (X[i]...
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
255
2
#include <algorithm> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<int, int> pii; typedef...
#include <algorithm> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<int, int> pii; typedef...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
289
4
#include <iostream> #include <string> using namespace std; #if 0 所用時間:0.5h 感想: #endif int solve(string X, string Y) { int rows = Y.size(); int cols = X.size(); int L[1001][1001] = {}; // L[y][x]の初期化 //テーブルLの更新 for (int r = 1; r <= rows; ++r) { for (int c = 1; c <= cols; ++c) { if (X[c] == Y[r])...
#include <iostream> #include <string> using namespace std; #if 0 所用時間:0.5h 感想: #endif int solve(string X, string Y) { int rows = Y.size(); int cols = X.size(); int L[1001][1001] = {}; // L[y][x]の初期化 //テーブルLの更新 for (int r = 1; r <= rows; ++r) { for (int c = 1; c <= cols; ++c) { if (X[c - 1] == Y...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
233
4
#include <iostream> #include <string> using namespace std; int A[1005][1005] = {}; int main() { int i, j, k, q; cin >> q; string a, b; for (i = 0; i < q; i++) { cin >> a >> b; int al = a.size(); int bl = b.size(); for (j = 1; j <= al; j++) { for (k = 1; k <= bl; k++) { if (a[j] ==...
#include <iostream> #include <string> using namespace std; int A[1005][1005] = {}; int main() { int i, j, k, q; cin >> q; string a, b; for (i = 0; i < q; i++) { cin >> a >> b; int al = a.size(); int bl = b.size(); for (j = 1; j <= al; j++) { for (k = 1; k <= bl; k++) { if (a[j - 1...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
198
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { string x, y; cin >> x >> y; int m = x.length(); int n = y.length(); vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0)); for (int i = 1; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { string x, y; cin >> x >> y; int m = x.length(); int n = y.length(); vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0)); for (int i = 1; i <= m; i++) { ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
219
4
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; #define MAX 1000 int main() { int n; cin >> n; string a, b; for (int i = 0; i < n; i++) { cin >> a >> b; int C[MAX + 1][MAX + 1] = {0}; for (int i = 1; i <= a.size(); i++) { for (int j = 1; j <=...
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; #define MAX 1000 int main() { int n; cin >> n; string a, b; for (int i = 0; i < n; i++) { cin >> a >> b; int C[MAX + 1][MAX + 1] = {0}; for (int i = 1; i <= a.size(); i++) { for (int j = 1; j <=...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
200
4
#include <bits/stdc++.h> using namespace std; int lcs(string X, string Y) { // staticにしないと実行時にスタックオーバーフローになる static int c[1001][1001]; int m = X.size(); int n = Y.size(); int maxl = 0; X = ' ' + X; Y = ' ' + Y; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 1; j <= n; j++) c[0][j] = ...
#include <bits/stdc++.h> using namespace std; int lcs(string X, string Y) { // staticにしないと実行時にスタックオーバーフローになる static int c[1001][1001]; int m = X.size(); int n = Y.size(); int maxl = 0; X = ' ' + X; Y = ' ' + Y; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 1; j <= n; j++) c[0][j] = ...
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
274
2
#include <cstdio> #include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m = x.length(); int n = y.length(); int c[m + 1][n + 1]; for (int i = 1; i < m; i++) { c[i][0] = 0; } for (int i = 1; i < n; i++) { c[0][i] = 0; } for (int i = 1; i <= m; i++) { ...
#include <cstdio> #include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m = x.length(); int n = y.length(); int c[m + 1][n + 1]; for (int i = 0; i <= m; i++) { c[i][0] = 0; } for (int i = 1; i <= n; i++) { c[0][i] = 0; } for (int i = 1; i <= m; i++) { ...
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
305
6
#include <iostream> using namespace std; const int MAX = 1001; short max(short a, short b) { if (a > b) { return a; } else { return b; } } short solve(string str1, string str2) { int len1 = str1.length(); int len2 = str2.length(); str1 = " " + str1; str2 = " " + str2; short LCS[MAX][MAX]; fo...
#include <iostream> using namespace std; const int MAX = 1001; short max(short a, short b) { if (a > b) { return a; } else { return b; } } short solve(string str1, string str2) { int len1 = str1.length(); int len2 = str2.length(); str1 = " " + str1; str2 = " " + str2; short LCS[MAX][MAX]; fo...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
325
4
#include <algorithm> #include <iostream> #include <vector> using namespace std; int lcs(const string &a, const string &b) { vector<vector<int>> dp(a.size(), vector<int>(b.size())); for (size_t i = 0; i < dp.size(); ++i) { for (size_t j = 0; j < dp[0].size(); ++j) { if (a.at(i) == b.at(j)) { dp[...
#include <algorithm> #include <iostream> #include <vector> using namespace std; int lcs(const string &a, const string &b) { vector<vector<int>> dp(a.size(), vector<int>(b.size())); for (size_t i = 0; i < dp.size(); ++i) { for (size_t j = 0; j < dp[0].size(); ++j) { if (a.at(i) == b.at(j)) { dp[...
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
269
2
#include <iostream> using namespace std; int ans(string a, string b) { int n = a.size(); int m = b.size(); int memo[n + 1][m + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { memo[i][j] = 0; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int re...
#include <iostream> using namespace std; int ans(string a, string b) { int n = a.size(); int m = b.size(); int memo[n + 1][m + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { memo[i][j] = 0; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int re...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
278
4
#include <iostream> using namespace std; int max_length(string x, string y) { int n = x.size(); int m = y.size(); int dp[n + 1][m + 1]; for (int i = 0; i < m; ++i) { dp[0][i] = 0; } for (int i = 1; i <= n; ++i) { dp[i][0] = 0; for (int j = 1; j <= m; ++j) { if (x[i - 1] == y[j - 1]) { ...
#include <iostream> using namespace std; int max_length(string x, string y) { int n = x.size(); int m = y.size(); int dp[n + 1][m + 1]; for (int i = 0; i <= m; ++i) { dp[0][i] = 0; } for (int i = 1; i <= n; ++i) { dp[i][0] = 0; for (int j = 1; j <= m; ++j) { if (x[i - 1] == y[j - 1]) { ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
251
2
#include <algorithm> #include <cstring> #include <iostream> #include <string> using namespace std; int dp[1001][1001]; int main() { int n; cin >> n; while (n--) { string X, Y; cin >> X >> Y; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= X.size(); ++i) { for (int j = 1; j <= Y.size(); ++j)...
#include <algorithm> #include <cstring> #include <iostream> #include <string> using namespace std; int dp[1001][1001]; int main() { int n; cin >> n; while (n--) { string X, Y; cin >> X >> Y; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= X.size(); ++i) { for (int j = 1; j <= Y.size(); ++j)...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
224
4
#include <cmath> #include <iostream> #include <stdio.h> #include <string> #define MAX_LENGTH 1000 #define NIL -1 using namespace std; // think easy make easy int q; // num of datasets string X; string Y; char map[MAX_LENGTH + 1][MAX_LENGTH + 1]; int findMaxLength(int x, int y) { // x:Xの終端.y:Yの終端(0オリジン) int val; ...
#include <cmath> #include <iostream> #include <stdio.h> #include <string> #define MAX_LENGTH 1000 #define NIL -1 using namespace std; // think easy make easy int q; // num of datasets string X; string Y; int map[MAX_LENGTH + 1][MAX_LENGTH + 1]; int findMaxLength(int x, int y) { // x:Xの終端.y:Yの終端(0オリジン) int val; ...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 18], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
1
283
6
#include <bits/stdc++.h> using namespace std; #define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++) #define REP(i, e) FOR(i, 0, e) #define all(o) (o).begin(), (o).end() #define psb(x) push_back(x) #define mp(x, y) make_pair((x), (y)) typedef long long ll; typedef pair<int, int> PII; const double EPS = 1e-10;...
#include <bits/stdc++.h> using namespace std; #define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++) #define REP(i, e) FOR(i, 0, e) #define all(o) (o).begin(), (o).end() #define psb(x) push_back(x) #define mp(x, y) make_pair((x), (y)) typedef long long ll; typedef pair<int, int> PII; const double EPS = 1e-10;...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
339
4
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; int main() { int q; cin >> q; for (int m = 0; m < q; m++) { string wordx, wordy; cin >> wordx >> wordy; int L[1000][1000] = {0}; for (int j = 0; j < wordy.size(); j++) { for (int i = 0; i < wor...
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; int main() { int q; cin >> q; for (int m = 0; m < q; m++) { string wordx, wordy; cin >> wordx >> wordy; int L[1010][1010] = {0}; for (int j = 0; j < wordy.size(); j++) { for (int i = 0; i < wor...
[["-", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["+", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 12, 13], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, ...
1
203
8
#include <algorithm> #include <iostream> #include <string> constexpr int MAX_XY = 1000; int lx, ly, q, dp[MAX_XY][MAX_XY]; std::string sx, sy; void fill_dp() { for (int i = 1; i <= lx; ++i) { for (int j = 1; j <= ly; ++j) { if (sx[i] == sy[j]) dp[i][j] = dp[i - 1][j - 1] + 1; else d...
#include <algorithm> #include <iostream> #include <string> constexpr int MAX_XY = 1010; int lx, ly, q, dp[MAX_XY][MAX_XY]; std::string sx, sy; void fill_dp() { for (int i = 1; i <= lx; ++i) { for (int j = 1; j <= ly; ++j) { if (sx[i - 1] == sy[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else ...
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
227
6
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <map> #include <math.h> #define INFTY (1 << 30) #define MAX 100000000 using namespa...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <map> #include <math.h> #define INFTY (1 << 30) #define MAX 100000000 using namespa...
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 13]]
1
330
2
#include <iostream> using namespace std; #include <string> string s, t; int dp[1001][1001]; int main() { int p; cin >> p; while (p > 0) { p--; cin >> s >> t; int n = s.size(); int m = t.size(); for (int i = 1; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= m; i++) dp[0][i] = ...
#include <iostream> using namespace std; #include <string> string s, t; int dp[1001][1001]; int main() { int p; cin >> p; while (p > 0) { p--; cin >> s >> t; int n = s.size(); int m = t.size(); for (int i = 1; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= m; i++) dp[0][i] = ...
[["-", 51, 16, 12, 69, 341, 342, 0, 16, 31, 22], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 31, 22]]
1
266
2
#include <iostream> #include <string> #include <vector> int main(int argc, char const *argv[]) { int q; std::cin >> q; for (size_t _ = 0; _ < q; _++) { std::string x, y; std::cin >> x; std::cin >> y; std::vector<std::vector<int>> dp(x.size() + 1, std::vector<...
#include <iostream> #include <string> #include <vector> int main(int argc, char const *argv[]) { int q; std::cin >> q; for (size_t _ = 0; _ < q; _++) { std::string x, y; std::cin >> x; std::cin >> y; std::vector<std::vector<int>> dp(x.size() + 1, std::vector<...
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22]]
1
256
4
#include <bits/stdc++.h> using namespace std; int dp[2000][2000]; int main(void) { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; while (n--) { string sa, sb; cin >> sa >> sb; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= sa.size(); i++) { for (int j = 1; j <= sb.size(); j...
#include <bits/stdc++.h> using namespace std; int dp[2000][2000]; int main(void) { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; while (n--) { string sa, sb; cin >> sa >> sb; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= sa.size(); i++) { for (int j = 1; j <= sb.size(); j...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
206
4
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; string s, t; int main() { int n; cin >> n; while (n--) { // dp[i][j] := // s???i??????????????§???t???j??????????????§?????£?????¨??????LCS vector<vector<int>> dp(2000, vector<int>(2000)); cin >> s...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; string s, t; int main() { int n; cin >> n; while (n--) { // dp[i][j] := // s???i??????????????§???t???j??????????????§?????£?????¨??????LCS vector<vector<int>> dp(2000, vector<int>(2000)); cin >> s...
[["-", 0, 16, 31, 69, 28, 69, 341, 342, 0, 13], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 12, 13], ["-", 51, 23, 0, 16, 31, 69, 341, 342, 0, 13], ["+", 0, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["+", 0, 16, 31, 69, 341, 342, 0, ...
1
317
8
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int dp[1001][1001]; int q; void solve() { char x[1001], y[1001]; scanf("%s %s", x, y); int lx = strlen(x); int ly = strlen(y); for (int i = 0; i <= lx; i++) { for (int j = 0; j <= ly; j++) { if (i == 0 || j == 0) ...
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int dp[1001][1001]; int q; void solve() { char x[1001], y[1001]; scanf("%s %s", x, y); int lx = strlen(x); int ly = strlen(y); for (int i = 0; i <= lx; i++) { for (int j = 0; j <= ly; j++) { if (i == 0 || j == 0) ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
240
4
#include <algorithm> #include <iostream> #include <string.h> #define MAX 10000 using namespace std; int lcs(string s1, string s2) { int C[MAX + 1][MAX + 1]; int m = s1.size(); int n = s2.size(); for (int i = 0; i <= m; ++i) { C[i][0] = 0; } for (int j = 0; j <= n; ++j) { C[0][j] = 0; } for (...
#include <algorithm> #include <iostream> #include <string.h> #define MAX 1000 using namespace std; int lcs(string s1, string s2) { int C[MAX + 1][MAX + 1]; int m = s1.size(); int n = s2.size(); for (int i = 0; i <= m; ++i) { C[i][0] = 0; } for (int j = 0; j <= n; ++j) { C[0][j] = 0; } for (i...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
276
2
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; int lcs(string X, string Y) { int n, m; int c[1001...
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; int lcs(string X, string Y) { int n, m; int c[1001...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 7, ...
1
315
12
#include <stdio.h> int hantei(char x[], char y[]) { int xn = 0, yn = 0, flag = 0, i, j, max = 0; int c[101][101]; while (flag == 0) { if (x[xn] == '\0') { xn++; } else { flag = 1; } } flag = 0; while (flag == 0) { if (y[yn] == '\0') { yn++; } else { flag = 1; ...
#include <stdio.h> int hantei(char x[], char y[]) { int xn = 0, yn = 0, flag = 0, i, j, max = 0; int c[1001][1001]; while (flag == 0) { if (x[xn] != '\0') { xn++; } else { flag = 1; } } flag = 0; while (flag == 0) { if (y[yn] != '\0') { yn++; } else { flag = 1...
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79]]
1
410
8
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
[["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
277
2
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; typedef pair<int, int> pii; vector<pii> P; string s, t, rev; const int MAX_N = 10001; int dp[MAX_N][MAX_N]; void trace(int i, int j) { if (dp[i][j] == dp[i - 1][j] && dp[i][j] == dp[i][j - 1]) { trace(i - 1, j...
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; typedef pair<int, int> pii; vector<pii> P; string s, t, rev; const int MAX_N = 1001; int dp[MAX_N][MAX_N]; void trace(int i, int j) { if (dp[i][j] == dp[i - 1][j] && dp[i][j] == dp[i][j - 1]) { trace(i - 1, j ...
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
457
6
#include "bits/stdc++.h" using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1]; int m = X.size(); int n = Y.size(); int maxl = 0; X = " " + X; Y = " " + Y; for (int i = 1; i <= m; ++i) { c[i][0] = 0; } for (int j = 1; j <= n; ++j) { c[0][j] = 0; }...
#include "bits/stdc++.h" using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1]; int m = X.length(); int n = Y.length(); int maxl = 0; X = " " + X; Y = " " + Y; for (int i = 0; i <= m; ++i) { c[i][0] = 0; } for (int j = 0; j <= n; ++j) { c[0][j] = 0;...
[["-", 0, 43, 49, 50, 51, 2, 63, 118, 119, 120], ["+", 0, 43, 49, 50, 51, 2, 63, 118, 119, 120], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 31, 22]]
1
304
10
#include <iostream> #include <string> using namespace std; static const int MAX = 1001; void lcs(string X, string Y) { int dp[MAX][MAX]; int i, j; int xLength = X.size(); int yLength = Y.size(); // initialize dp[][] for (i = 1; i <= xLength; i++) dp[i][0] = 0; for (i = 1; i <= yLength; i++) dp[...
#include <iostream> #include <string> using namespace std; static const int MAX = 1001; void lcs(string X, string Y) { int dp[MAX][MAX]; int i, j; int xLength = X.size(); int yLength = Y.size(); // initialize dp[][] for (i = 1; i <= xLength; i++) dp[i][0] = 0; for (i = 1; i <= yLength; i++) dp[...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
282
4
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int Q = 0; string X, Y; cin >> Q; for (int q = 0; q < Q; q++) { cin >> X >> Y; int len[1001][1001] = {}; for (int s = 1; s <= X.length(); s++) { for (int t = 1; t <= Y.length(); t++) { if (X...
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int Q = 0; string X, Y; cin >> Q; for (int q = 0; q < Q; q++) { cin >> X >> Y; int len[1001][1001] = {}; for (int s = 1; s <= X.length(); s++) { for (int t = 1; t <= Y.length(); t++) { if (X...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
190
4
#include <iostream> #include <string> using namespace std; // ???????????§???????????§?????§?????? int DP[1024][1024] = {}; int main() { int N; cin >> N; for (int c = 0; c < N; ++c) { string X, Y; cin >> X >> Y; int xlen = (int)X.size(); int ylen = (int)Y.size(); for (int i = 0; i <= xlen; ...
#include <iostream> #include <string> using namespace std; // ???????????§???????????§?????§?????? int DP[1024][1024] = {}; int main() { int N; cin >> N; for (int c = 0; c < N; ++c) { string X, Y; cin >> X >> Y; int xlen = (int)X.size(); int ylen = (int)Y.size(); for (int i = 0; i <= xlen; ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
252
4
#include <iostream> #include <string> using namespace std; // L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS int L[1001][1001] = {}; int main() { int testnum; cin >> testnum; for (int t = 0; t < testnum; ++t) { string X, Y; cin >> X >> Y; for (int i = 1; i <= X.length(); ++i) { for (int j = 1; j <= Y....
#include <iostream> #include <string> using namespace std; // L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS int L[1001][1001] = {}; int main() { int testnum; cin >> testnum; for (int t = 0; t < testnum; ++t) { string X, Y; cin >> X >> Y; for (int i = 1; i <= X.length(); ++i) { for (int j = 1; j <= Y....
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
190
4
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int lcs(string a, string b) { int longest_length = 0; int m = a.size(), n = b.size(); int table[m + 1][n + 1]; for (int i = 0; i < m + 1; i++) table[i][0] = 0; for (int i = 0; i < n + 1; i++) table[0][i...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int lcs(string a, string b) { int longest_length = 0; int m = a.size(), n = b.size(); int table[m + 1][n + 1]; for (int i = 0; i < m + 1; i++) table[i][0] = 0; for (int i = 0; i < n + 1; i++) table[0][i...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
292
4
#include <algorithm> #include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1]; int m = X.size(); int n = Y.size(); int maxl = 0; X = " " + X; Y = " " + Y; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 0; j <= n;...
#include <algorithm> #include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string X, string Y) { int c[N + 1][N + 1]; int m = X.size(); int n = Y.size(); int maxl = 0; X = " " + X; Y = " " + Y; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 0; j <= n;...
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
302
2
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int q; cin >> q; for (int i = 0; i < q; i++) { string x, y; cin >> x >> y; int nx, ny; nx = x.size(); ny = y.size(); vector<vector<int>> lcs(nx + 1, vector<int>(ny + 1, 0)); for (int i = ...
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int q; cin >> q; for (int i = 0; i < q; i++) { string x, y; cin >> x >> y; int nx, ny; nx = x.size(); ny = y.size(); vector<vector<int>> lcs(nx + 1, vector<int>(ny + 1, 0)); for (int i = ...
[["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46]]
1
209
6
#include <algorithm> #include <iostream> #include <string> using namespace std; #define MAX 1000 int dp[MAX + 1][MAX + 1]; int LCS(string STR1, string STR2) { int length1 = STR1.size(); int length2 = STR2.size(); //???????????¨???????????????????????? STR1 = ' ' + STR1; STR2 = ' ' + STR2; for (int i = 0; i ...
#include <algorithm> #include <iostream> #include <string> using namespace std; #define MAX 1000 int dp[MAX + 1][MAX + 1]; int LCS(string STR1, string STR2) { int length1 = STR1.size(); int length2 = STR2.size(); STR1 = ' ' + STR1; STR2 = ' ' + STR2; for (int i = 0; i <= length1; i++) { for (int l = 0; l ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
1
273
6
#include <algorithm> #include <iostream> #include <string> #define int long long using namespace std; signed main() { int n; cin >> n; for (int c = 0; c < n; c++) { string x, y; cin >> x >> y; int dp[x.size() + 1][y.size() + 1]; for (int i = 0; i < x.size() + 1; i++) { dp[i][0] = 0; } ...
#include <algorithm> #include <iostream> #include <string> #define int long long using namespace std; signed main() { int n; cin >> n; for (int c = 0; c < n; c++) { string x, y; cin >> x >> y; int dp[x.size() + 1][y.size() + 1]; for (int i = 0; i < x.size() + 1; i++) { dp[i][0] = 0; } ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
275
4
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; // --------------------- // repetition #define FOR(i, a, b) for (...
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; // --------------------- // repetition #define FOR(i, a, b) for (...
[["-", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 12, 13], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, ...
1
289
8
#include <algorithm> #include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string x, string y) { int c[N + 1][N + 1], maxl = 0, i, j; int m = x.size(); int n = y.size(); x = ' ' + x; y = ' ' + y; for (i = 1; i <= m; i++) c[i][0] = 0; for (i = 1; i <= n; i++) ...
#include <algorithm> #include <iostream> #include <string> using namespace std; static const int N = 1000; int lcs(string x, string y) { int c[N + 1][N + 1], maxl = 0, i, j; int m = x.size(); int n = y.size(); x = ' ' + x; y = ' ' + y; for (i = 1; i <= m; i++) c[i][0] = 0; for (i = 0; i <= n; i++) ...
[["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
298
6
#include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m = x.size(); int n = y.size(); int c[m + 1][n + 1]; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int i = 1; i <= n; i++) c[0][i] = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { ...
#include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m = x.size(); int n = y.size(); int c[m + 1][n + 1]; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int i = 1; i <= n; i++) c[0][i] = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
256
4
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; int get_LCS(string x, string y) { int nx = x.size(), ny = y.size(); int dp[nx + 1][ny + 1]; for (int i =...
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; int get_LCS(string x, string y) { int nx = x.size(), ny = y.size(); int dp[nx + 1][ny + 1]; for (int i =...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
288
4
#include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; cin >> n; string x, y; while (n--) { fill((int *)dp, (int *)(dp + 1002), 0); cin >> x >> y; for (int i = 1; i <= x.size(); i++) { for (int j = 1; j <= y.size(); j++) { ...
#include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; cin >> n; string x, y; while (n--) { fill((int *)dp, (int *)(dp + 1002), 0); cin >> x >> y; for (int i = 1; i <= x.size(); i++) { for (int j = 1; j <= y.size(); j++) { ...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
200
4
#include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; cin >> n; string x, y; while (n--) { cin >> x >> y; for (int i = 1; i <= x.size(); i++) { for (int j = 1; j <= y.size(); j++) { if (x[i] == y[j]) dp[i][j] = dp...
#include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; cin >> n; string x, y; while (n--) { cin >> x >> y; for (int i = 1; i <= x.size(); i++) { for (int j = 1; j <= y.size(); j++) { if (x[i - 1] == y[j - 1]) dp[i]...
[["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
179
4
#include <iostream> #include <string> #define MAX_N 1000 #define MAX_M 1000 int n, m; std::string s, t; int dp[MAX_N + 1][MAX_M + 1]; void solve() { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (s[i + 1] == t[j + 1]) { dp[i + 1][j + 1] = dp[i][j] + 1; } else { dp[...
#include <iostream> #include <string> #define MAX_N 1000 #define MAX_M 1000 int n, m; std::string s, t; int dp[MAX_N + 1][MAX_M + 1]; void solve() { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (s[i] == t[j]) { dp[i + 1][j + 1] = dp[i][j] + 1; } else { dp[i + 1][j...
[["-", 51, 16, 31, 69, 341, 342, 0, 16, 17, 72], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
228
4
#define PI 3.14159265359 #define INF 2000000000 #define MAX 500000 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; void LCS(string X, string Y) { int c[1000][1...
#define PI 3.14159265359 #define INF 2000000000 #define MAX 500000 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; void LCS(string X, string Y) { int c[1002][1...
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], [...
1
271
8
#include <iostream> using namespace std; #include <algorithm> #include <cstring> #include <string> int dp[1002][1002] = {0}; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { string x, y; int cnt = 0; cin >> x >> y; memset(dp, 0, sizeof(dp)); for (int j = 1; j <= x.size(); ++j) { ...
#include <iostream> using namespace std; #include <algorithm> #include <cstring> #include <string> int dp[1002][1002] = {0}; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { string x, y; int cnt = 0; cin >> x >> y; memset(dp, 0, sizeof(dp)); for (int j = 1; j <= x.size(); ++j) { ...
[["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
234
2
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int p[1001][1001] = {0}; int main() { int i, j, q, e, l, z, m, u, n; char s[2001], c[2001]; cin >> q; for (e = 0; e < q; e++) { scanf("%s %s", s, c); l = strlen(s); z = strlen(c); for (i = 0; i ...
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int p[1001][1001] = {0}; int main() { int i, j, q, e, l, z, m, u, n; char s[2001], c[2001]; cin >> q; for (e = 0; e < q; e++) { scanf("%s %s", s, c); l = strlen(s); z = strlen(c); for (i = 0; i ...
[["+", 0, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 69, 28, 69, 341, 342, 0, 16, 12, 13], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
260
4
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int c[1010][1010]; void lcs(char X[], char Y[]) { int m = strlen(X); int n = strlen(Y); int i, j; for (i = 1; i <= m; i++) c[i][0] = 0; for (j = 1; j <= m; j++) c[0][j] = 0; for (i = 1; i <= m; i++) { for (j = 1; j ...
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int c[1010][1010]; void lcs(char X[], char Y[]) { int m = strlen(X); int n = strlen(Y); int i, j; for (i = 1; i <= m; i++) c[i][0] = 0; for (j = 1; j <= n; j++) c[0][j] = 0; for (i = 1; i <= m; i++) { for (j = 1; j ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
295
6
#include <algorithm> #include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m, n, c[1001][1001], i, j, maxl = 0; m = x.size(); n = y.size(); x = ' ' + x; y = ' ' + y; for (i = 0; i <= m; i++) { c[i][0] = 0; } for (j = 1; j <= n; j++) { c[0][j] = 0; }...
#include <algorithm> #include <iostream> #include <string> using namespace std; int lcs(string x, string y) { int m, n, c[1001][1001], i, j, maxl = 0; m = x.size(); n = y.size(); x = ' ' + x; y = ' ' + y; for (i = 0; i <= m; i++) { c[i][0] = 0; } for (j = 1; j <= n; j++) { c[0][j] = 0; }...
[["-", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
301
4
#include <iostream> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long signed int ll; constexpr ll NIL = -20000000000; int g[101][101], n, d[101], f[101]; int main() { cin >> n; for (int i = 0; i < n; i++) { int u, k, v; cin >> u...
#include <iostream> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long signed int ll; constexpr ll NIL = -20000000000; int g[101][101], n, d[101], f[101]; int main() { cin >> n; for (int i = 0; i < n; i++) { int u, k, v; cin >> u...
[["+", 0, 7, 8, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 7, 8, 57, 64, 9, 0, 93, 0, 35]]
1
348
2
#include <iostream> using namespace std; int adja[101][101]; int d[101], f[101], cnt; void dfs(int u) { d[u] = ++cnt; for (int i = 0, v; (v = adja[u][i]) > 0; ++i) { if (v > 0) continue; dfs(v); } f[u] = ++cnt; } int main() { int n, k, u; cin >> n; for (int i = 0; i < n; ++i) { cin >...
#include <iostream> using namespace std; int adja[101][101]; int d[101], f[101], cnt; void dfs(int u) { d[u] = ++cnt; for (int i = 0, v; (v = adja[u][i]) > 0; ++i) { if (d[v] > 0) continue; dfs(v); } f[u] = ++cnt; } int main() { int n, k, u; cin >> n; for (int i = 0; i < n; ++i) { ci...
[["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73]]
1
215
3
#include <iostream> #include <queue> using namespace std; int a[101][101]; int n = 0; int found[101]; int ended[101]; int aaa(int i, int time); int main() { for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) a[i][j] = 0; int u, k, v; cin >> n; for (int i = 0; i < n; i++) { cin >> u >> k...
#include <iostream> #include <queue> using namespace std; int a[101][101]; int n = 0; int found[101]; int ended[101]; int aaa(int i, int time); int main() { for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) a[i][j] = 0; int u, k, v; cin >> n; for (int i = 0; i < n; i++) { ...
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
363
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> #include <vector> using namespace std; struct Node { int k, d, f; vector<int> v; }; #define MAX_N 100 Node node[MAX_N + 1]; int stamp = 1; ; void df...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> #include <vector> using namespace std; struct Node { int k, d, f; vector<int> v; }; #define MAX_N 100 Node node[MAX_N + 1]; int stamp = 1; void dfs(...
[["-", 36, 36, 36, 36, 0, 30, 0, 42, 0, 35], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
320
3
#include <algorithm> #include <iostream> #include <stack> #include <string> #include <vector> struct node { int num; std::vector<int> child; }; int recurcive(node nodes[], int d[100], int f[100], int n, int count) { d[n] = count++; for (size_t i = 0; i < nodes[n].child.size(); i++) { if (d[nodes[n].child[...
#include <algorithm> #include <iostream> #include <stack> #include <string> #include <vector> struct node { int num; std::vector<int> child; }; int recurcive(node nodes[], int d[100], int f[100], int n, int count) { d[n] = count++; for (size_t i = 0; i < nodes[n].child.size(); i++) { if (d[nodes[n].child[...
[["+", 75, 76, 0, 9, 0, 1, 0, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 27, 17, 68], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
1
432
3
#include <cstdio> #include <iostream> #include <stack> using namespace std; static const int MAX_NUM = 101; static const int NO_VISIT = 0; static const int NOW_VISIT = 1; static const int END_VISIT = 2; void DSF(int *matrix, int num) { int i, j; int ttime = 0; int stime[MAX_NUM + 1] = {0}; int etime[MAX_NUM ...
#include <cstdio> #include <iostream> #include <stack> using namespace std; static const int MAX_NUM = 101; static const int NO_VISIT = 0; static const int NOW_VISIT = 1; static const int END_VISIT = 2; void DSF(int *matrix, int num) { int i, j; int ttime = 0; int stime[MAX_NUM + 1] = {0}; int etime[MAX_NUM ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
456
6
#include <stack> #include <stdio.h> #define MAX 100 enum SATE { NOT_VISIT, DISCOVER, FOUND }; int G[MAX + 1][MAX + 1], d[MAX + 1], f[MAX + 1], STATE[MAX + 1]; int n, tt; std::stack<int> S; void dfs(int i) { S.push(i); STATE[i] = DISCOVER; d[i] = ++tt; for (int j = 1; j <= n; ++j) { if (G[i][j] != -1 &&...
#include <stack> #include <stdio.h> #define MAX 100 enum SATE { NOT_VISIT, DISCOVER, FOUND }; int G[MAX + 1][MAX + 1], d[MAX + 1], f[MAX + 1], STATE[MAX + 1]; int n, tt; std::stack<int> S; void dfs(int i) { S.push(i); STATE[i] = DISCOVER; d[i] = ++tt; for (int j = 1; j <= n; ++j) { if (G[i][j] != 1 ||...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
1
371
4
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GREY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) ...
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GREY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) ...
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
507
2
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
[["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 13], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 25]]
1
337
4
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, tt; int color[N], nt[N], M[N][N], d[N], f[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) re...
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, tt; int color[N], nt[N], M[N][N], d[N], f[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) re...
[["-", 64, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 75, 76, 0, 9, 0, 1, 0, 16, 17, 60], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 0, 7, 8, 9, 0, 7, 26, 27, 17, 68], ["+", 0, 7, ...
1
510
8
#include <stdio.h> #define N 100 #define WHITE 0 #define GRAY 1 #define BLACK 2 int n, M[N][N]; int color[N], d[N], f[N], tt; void dfs_visit(int u) { int v; color[u] = GRAY; d[u] = ++tt; for (v = 0; v < n; v++) { if (M[u][v] == 0) continue; if (color[v] == WHITE) { dfs_visit(v); } } ...
#include <stdio.h> #define N 100 #define WHITE 0 #define GRAY 1 #define BLACK 2 int n, M[N][N]; int color[N], d[N], f[N], tt; void dfs_visit(int u) { int v; color[u] = GRAY; d[u] = ++tt; for (v = 0; v < n; v++) { if (M[u][v] == 0) continue; if (color[v] == WHITE) { dfs_visit(v); } } ...
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
1
374
1
#include <iostream> using namespace std; const int MAX = 100; void search(bool graph[MAX][MAX], int find[], int done[], int n, int u, int &count) { count++; find[u] = count; for (int i = 0; i < n; i++) { if (graph[u][i] && find[i] == 0) { search(graph, find, done, n, i, count); } }...
#include <iostream> using namespace std; const int MAX = 100; void search(bool graph[MAX][MAX], int find[], int done[], int n, int u, int &count) { count++; find[u] = count; for (int i = 0; i < n; i++) { if (graph[u][i] && find[i] == 0) { search(graph, find, done, n, i, count); } }...
[["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
330
2
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> bool table[102][102] = {}; int color[102] = {}; // 0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢?????? int n, counter = 0; int t_visit[102] = {}; int t_finish[102] = {}; void DFS(int y) { for (int j = 0; j <= n - 1; j++) { //?¨????or??¢?´¢???????????£??????????????? ...
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> bool table[102][102] = {}; int color[102] = {}; // 0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢?????? int n, counter = 0; int t_visit[102] = {}; int t_finish[102] = {}; void DFS(int y) { for (int j = 0; j <= n - 1; j++) { //?¨????or??¢?´¢???????????£??????????????? ...
[["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
349
2
#include <stdio.h> int d[100], f[100], n, g[100][100], time = 1; int func(int n) { d[n] = time++; int i, j; for (i = 0; i < n; i++) { if (g[n][i] == 1 && d[i] == 0) { func(i); } } f[n] = time++; } int main(void) { int i, j, u, k, v; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("...
#include <stdio.h> int d[100], f[100], n, g[100][100], time = 1; int func(int m) { d[m] = time++; int i, j; for (i = 0; i < n; i++) { if (g[m][i] == 1 && d[i] == 0) { func(i); } } f[m] = time++; } int main(void) { int i, j, u, k, v; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 49, 22], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 49, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 31, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["+", 31, 16, 31, 69, 28, 69, 341, 342, 0, 22]]
1
268
8
#include <iostream> using namespace std; int G[105][105] = {}; int d[105] = {}, f[105] = {}; int N, T = 0; void Gprint(int n) { cout << "\\|"; for (int i = 0; i < n; i++) cout << i + 1; cout << endl; for (int i = 0; i < n + 2; i++) cout << "-"; cout << endl; for (int i = 0; i < n; i++) { cout ...
#include <iostream> using namespace std; int G[105][105] = {}; int d[105] = {}, f[105] = {}; int N, T = 0; void Gprint(int n) { cout << "\\|"; for (int i = 0; i < n; i++) cout << i + 1; cout << endl; for (int i = 0; i < n + 2; i++) cout << "-"; cout << endl; for (int i = 0; i < n; i++) { cout ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
366
5
#include <iostream> using namespace std; int time1 = 0; int a[110][110] = {}; int d[110] = {}; int f[110] = {}; int n; int p; void dfs(int cur) { if (d[cur] == 0) { d[cur] = time1; } time1 += 1; f[cur] = time1; for (int dst = 1; dst <= n; dst++) { if (a[cur][dst] == 1 && d[dst] == 0) { a[cur]...
#include <iostream> using namespace std; int time1 = 0; int a[110][110] = {}; int d[110] = {}; int f[110] = {}; int n; int p; void dfs(int cur) { if (d[cur] == 0) { d[cur] = time1; } time1 += 1; f[cur] = time1; for (int dst = 1; dst <= n; dst++) { if (a[cur][dst] == 1 && d[dst] == 0) { a[cur]...
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
351
4
#include <iostream> using namespace std; int m[101][101]; int visit[101]; int d[101]; int f[101]; int n, t; void dfs(int u) { visit[u] = 1; d[u] = t; t++; for (int i = 0; i < n; ++i) { if (m[u][i] == 1 && visit[i] == 0) { dfs(i); } } f[u] = t; t++; } main() { int u, k, v; cin >> n;...
#include <iostream> using namespace std; int m[101][101]; int visit[101]; int d[101]; int f[101]; int n, t; void dfs(int u) { visit[u] = 1; d[u] = t; t++; for (int i = 0; i < n; ++i) { if (m[u][i] == 1 && visit[i] == 0) { dfs(i); } } f[u] = t; t++; } main() { int u, k, v; t = 1; ...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
268
4
#include <iostream> using namespace std; int n, t = 0; int v[100][100]; int d[100], f[100], r[101]; void st(int id) { if (!r[id]) { r[id]++; d[id - 1] = ++t; for (int i = 0; i < n; i++) if (v[id - 1][i]) st(i + 1); f[id - 1] = ++t; } } int main() { cin >> n; for (int i = 0; i <...
#include <iostream> using namespace std; int n, t = 0; int v[100][100]; int d[100], f[100], r[101]; void st(int id) { if (!r[id]) { r[id]++; d[id - 1] = ++t; for (int i = 0; i < n; i++) if (v[id - 1][i]) st(i + 1); f[id - 1] = ++t; } } int main() { cin >> n; for (int i = 0; i <...
[["+", 8, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 8, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
250
2
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; // u に隣接する v を番号順に取得 int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; ...
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) ...
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
505
2
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) { ...
#include <iostream> #include <stack> using namespace std; static const int N = 100; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n, M[N][N]; int color[N], d[N], f[N], tt; int nt[N]; int next(int u) { for (int v = nt[u]; v < n; v++) { nt[u] = v + 1; if (M[u][v]) { ...
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
517
2
config = { input : 'tmp', newline : '\r\n' }; // win // config = { input: '/dev/stdin', newline: '\n' }; // linux line = require('fs') .readFileSync(config.input, 'ascii') .trim() .split(config.newline); n = Number(line.shift()); adj = {}; for (i in line) { ary = line[i].split(' ...
// config = { input: 'tmp', newline: '\r\n' }; // win config = { input : '/dev/stdin', newline : '\n' }; // linux line = require('fs') .readFileSync(config.input, 'ascii') .trim() .split(config.newline); n = Number(line.shift()); adj = {}; for (i in line) { ary = line[i].split(' ...
[["-", 0, 11, 12, 500, 0, 569, 51, 557, 0, 491], ["+", 0, 11, 12, 500, 0, 569, 51, 557, 0, 491], ["-", 0, 11, 12, 500, 0, 569, 51, 557, 0, 44]]
2
275
3
#include <stdbool.h> #include <stdio.h> #define N 100 #define WHITE 0 #define BLACK 2 #define GRAY 1 #define INF -1 int GX[N][N], x, color[N], Q[N], d[N], head, tail; bool isEnpty() { if (tail == head) true; else false; } void enqueue(int x) { Q[tail] = x; if (tail + 1 == N) tail = 0; else ...
#include <stdbool.h> #include <stdio.h> #define N 101 #define WHITE 0 #define BLACK 2 #define GRAY 1 #define INF -1 int GX[N][N], x, color[N], Q[N], d[N], head, tail; bool isEnpty() { if (tail == head) true; else false; } void enqueue(int x) { Q[tail] = x; if (tail + 1 == N) tail = 0; else ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
0
475
6
#include <stdio.h> int V[150][150], d[150], f[150], color[150], Q[150]; int time, n, head, tail; void enqueue(int x) { Q[tail] = x; tail++; } int dequeue() { int x = Q[head]; head++; return x; } BFS(int s) { int u, v; for (u = 1; u <= n - s; u++) { color[u] = 0; d[u] = -1; } color[s] = ...
#include <stdio.h> int V[150][150], d[150], f[150], color[150], Q[150]; int time, n, head, tail; void enqueue(int x) { Q[tail] = x; tail++; } int dequeue() { int x = Q[head]; head++; return x; } BFS(int s) { int u, v; for (u = 1; u <= n; u++) { color[u] = 0; d[u] = -1; } color[s] = 1; ...
[["-", 0, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 0, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
0
354
2
#include <limits.h> #include <stdio.h> #define N 101 #define WHITE 0 #define GRAY 1 #define BLACK 2 int Q[N], M[N][N], color[N], d[N], n, f = 1, c = 1; void Enqueue(int n) { Q[f] = n; f++; if (f == N) f = 1; } int Dequeue() { int x = c; c++; if (c == N) c = 1; return Q[x]; } void BFS(int s) {...
#include <limits.h> #include <stdio.h> #define N 101 #define WHITE 0 #define GRAY 1 #define BLACK 2 int Q[N], M[N][N], color[N], d[N], n, f = 1, c = 1; void Enqueue(int n) { Q[f] = n; f++; if (f == N) f = 1; } int Dequeue() { int x = c; c++; if (c == N) c = 1; return Q[x]; } void BFS(int s) {...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
0
428
2
#include <limits.h> #include <stdio.h> #define MAX 105 #define WHITE 0 #define GRAY 1 #define BLACK 2 void BFS(void); void Enqueue(int); int Dequeue(void); int G[MAX][MAX]; int Q[MAX]; int d[MAX]; int f[MAX]; int color[MAX]; int n; int time; int s; int head = 0; int tail = 0; int main() { int i, j, u, k, next; ...
#include <limits.h> #include <stdio.h> #define MAX 105 #define WHITE 0 #define GRAY 1 #define BLACK 2 void BFS(void); void Enqueue(int); int Dequeue(void); int G[MAX][MAX]; int Q[MAX]; int d[MAX]; int f[MAX]; int color[MAX]; int n; int time; int s; int head = 0; int tail = 0; int main() { int i, j, u, k, next; ...
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
0
447
2
#include <limits.h> #include <stdio.h> #define N 101 #define Black 2 #define White 0 #define Gray 1 int n = 0; // int z=0; int G[N][N]; int d[N]; // int f[N]; int color[N]; int que[N]; int head = 0; int tail = 0; void Enqueue(int s) { que[tail] = s; tail++; } int Dequeue() { int y; y = que[head]; head += ...
#include <limits.h> #include <stdio.h> #define N 101 #define Black 2 #define White 0 #define Gray 1 int n = 0; // int z=0; int G[N][N]; int d[N]; // int f[N]; int color[N]; int que[N]; int head = 0; int tail = 0; void Enqueue(int s) { que[tail] = s; tail++; } int Dequeue() { int y; y = que[head]; head += ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
0
416
2
#include <limits.h> #include <stdio.h> #define WHITE 1 #define GRAY 2 #define BLACK -1 int Adj[101][101], d[101], time, n; int head, tail; int Q[100]; enque(int x) { Q[tail] = x; if (tail + 1 == 100) { tail = 0; } else { tail++; } } int deque() { int x = Q[head]; if (head + 1 == 100) { head ...
#include <limits.h> #include <stdio.h> #define WHITE 1 #define GRAY 2 #define BLACK -1 int Adj[101][101], d[101], time, n; int head, tail; int Q[100]; enque(int x) { Q[tail] = x; if (tail + 1 == 100) { tail = 0; } else { tail++; } } int deque() { int x = Q[head]; if (head + 1 == 100) { head ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
0
414
2
#include <stdio.h> #include <stdlib.h> #define INF -1000 typedef struct { int d; int f; } timestamp; typedef struct { int u; int k; int *v; } graph; graph g[110]; timestamp t[110]; int mytime = 0; int q[110]; void bfs(void); int main(void) { int i, j, n; scanf("%d", &n); for (i = 0; i <= n; i++)...
#include <stdio.h> #include <stdlib.h> #define INF -1 typedef struct { int d; int f; } timestamp; typedef struct { int u; int k; int *v; } graph; graph g[110]; timestamp t[110]; int mytime = 0; int q[110]; void bfs(void); int main(void) { int i, j, n; scanf("%d", &n); for (i = 0; i <= n; i++) { ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
423
2
#include <stdio.h> #define INF 2147483647 void bfs(int); void enqueue(int); int dequeue(); int n, head, tail, Q[100], color[100], d[100], A[100][100]; int main() { int i, j, u, k, v; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) A[i][j] = 0; } for (i = 0; i < n; i++) { ...
#include <stdio.h> #define INF 2147483647 void bfs(int); void enqueue(int); int dequeue(); int n, head, tail, Q[100], color[100], d[100], A[100][100]; int main() { int i, j, u, k, v; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) A[i][j] = 0; } for (i = 0; i < n; i++) { ...
[["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60]]
0
448
2
#include <stdio.h> #include <stdlib.h> #define N 101 #define INF -1 int Q[N]; int head, tail; int M[N][N] = {{}}; int d[N]; int n; char color[N]; void enqueue(int key) { Q[tail] = key; if (tail == N - 1) { tail = 0; } else { tail++; } } int dequeue() { int x; x = Q[head]; if (head == N - 1) { ...
#include <stdio.h> #include <stdlib.h> #define N 101 #define INF -1 int Q[N]; int head, tail; int M[N][N] = {{}}; int d[N]; int n; char color[N]; void enqueue(int key) { Q[tail] = key; if (tail == N - 1) { tail = 0; } else { tail++; } } int dequeue() { int x; x = Q[head]; if (head == N - 1) { ...
[["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
405
2
/* C Breadth First Search */ #include <stdio.h> #define WHITE 0 #define GRAY 1 #define BLACK 2 int n; int time; int A[101][101]; /* 1<= n <= 100 */ int color[101]; int d[101]; int head = 0, tail = 0; void BFS(int s); void Enqueue(int Q[], int s); int Dequeue(int Q[]); int main() { int i, j; int u, k, v; scanf...
/* C Breadth First Search */ #include <stdio.h> #define WHITE 0 #define GRAY 1 #define BLACK 2 int n; int time; int A[101][101]; /* 1<= n <= 100 */ int color[101]; int d[101]; int head = 0, tail = 0; void BFS(int s); void Enqueue(int Q[], int s); int Dequeue(int Q[]); int main() { int i, j; int u, k, v; scanf...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
0
450
2
#include <stdio.h> #define MAX 102 #define WHITE 0 #define BLACK 1 #define GRAY 2 #define NIL -1 void init(); int n, head = 0, tail = 0, color[MAX]; int d[MAX], edge[MAX], G[MAX][MAX]; void init() { int i; for (i = 0; i <= n; i++) { color[i] = WHITE; d[i] = 10000000; } } /*void Enqueue(int x){ if((...
#include <stdio.h> #define MAX 102 #define WHITE 0 #define BLACK 1 #define GRAY 2 #define NIL -1 void init(); int n, head = 0, tail = 0, color[MAX]; int d[MAX], edge[MAX], G[MAX][MAX]; void init() { int i; for (i = 0; i <= n; i++) { color[i] = WHITE; d[i] = 10000000; } } /*void Enqueue(int x){ if((...
[["-", 8, 9, 0, 7, 8, 9, 0, 37, 0, 38], ["-", 8, 9, 0, 7, 8, 9, 0, 37, 0, 13], ["-", 8, 9, 0, 7, 8, 9, 0, 37, 0, 35]]
0
491
3
n = gets.to_i line = [] (1..n).each{ |i| line[i] = gets.split.map(&:to_i)[2..-1] } h = 0 visited = Array.new(n+1, -1) visited[1] = 0 while true f = false (1..n).each do |i| if visited[i] == h f = true line[i].each{ |j| visited[j] = h+1 if visited[i] == -1 } end end break unless f h += 1 ...
n = gets.to_i line = [] (1..n).each{ |i| line[i] = gets.split.map(&:to_i)[2..-1] } h = 0 visited = Array.new(n+1, -1) visited[1] = 0 while true f = false (1..n).each do |i| if visited[i] == h f = true line[i].each{ |j| visited[j] = h+1 if visited[j] == -1 } end end break unless f h += 1 ...
[["-", 8, 734, 0, 751, 15, 738, 31, 742, 0, 22], ["+", 8, 734, 0, 751, 15, 738, 31, 742, 0, 22]]
4
150
2
N = gets.to_i G = (1..N).map{ Array.new(N, 0) } N.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| G[u - 1][vi - 1] = 1 end end Q = [0] #?§????0?????\??£????????\??? D = Array.new(N, -1) D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨???????????? while Q.size > 0 cur = Q.shift (0.....
N = gets.to_i G = (1..N).map{ Array.new(N, 0) } N.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| G[u - 1][vi - 1] = 1 end end Q = [0] #?§????0?????\??£????????\??? D = Array.new(N, -1) D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨???????????? while Q.size > 0 cur = Q.shift (0.....
[["-", 8, 736, 0, 121, 64, 749, 0, 738, 17, 18], ["+", 8, 736, 0, 121, 64, 749, 0, 738, 17, 151]]
4
186
2
def traverse a = [] len = 1 now = 0 $list[now] = 1 loop{ $n.times do |i| if $m[now][i] == 1 && $list[i] == 0 a << [i, len + 1] $data[i].len = len $list[i] = 1 end end return nil if a.empty? nex = a.shift now = nex[0] len = nex[1] } end D = Struct.new(:len) $n = gets.to_i $ti...
def traverse a = [] len = 1 now = 0 $list[now] = 1 loop{ $n.times do |i| if $m[now][i] == 1 && $list[i] == 0 a << [i, len + 1] $data[i].len = len $list[i] = 1 end end return nil if a.empty? nex = a.shift now = nex[0] len = nex[1] } end D = Struct.new(:len) $n = gets.to_i $ti...
[["+", 196, 196, 8, 734, 0, 652, 3, 4, 0, 24], ["+", 8, 734, 0, 652, 3, 4, 0, 748, 17, 33], ["+", 8, 734, 0, 652, 3, 4, 0, 748, 439, 612], ["+", 196, 196, 8, 734, 0, 652, 3, 4, 0, 25]]
4
241
4
#encoding: utf-8 $map = [] $depth = [0] * 100 $vis = [false] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end e...
#encoding: utf-8 $map = [] $depth = [-1] * 100 $vis = [false] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end ...
[["-", 0, 493, 0, 662, 12, 738, 31, 516, 0, 612], ["+", 0, 662, 12, 738, 31, 516, 0, 748, 17, 33], ["+", 0, 662, 12, 738, 31, 516, 0, 748, 439, 612]]
4
243
3
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n queue = [0] for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 while len(queue) != 0: i = queue.pop(0) for j in range(n): if (graph...
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n queue = [0] for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 f[0] = 1 while len(queue) != 0: i = queue.pop(0) for j in range(n): ...
[["+", 0, 656, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 0, 70], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 206, 612], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612]]
5
216
6
N= int(input()) E = [input().split()[2:] for _ in [0]*N] Q = [0] L = [0] + [-1]*N def func(ide): for i in E[ide]: i = int(i) - 1 if L[i] < 0 :L[i] = L[ide] +1 ; Q+= [i] while Q:top = Q.pop(0);func(top) for i in range(N):print(i + 1 ,int(L[i]))
N= int(input()) E = [input().split()[2:] for _ in [0]*N] Q = [0] L = [0] + [-1]*N def func(ide): global Q for i in E[ide]: i = int(i) - 1 if L[i] < 0 :L[i] = L[ide] +1 ;Q += [i] while Q:top = Q.pop(0);func(top) for i in range(N):print(i + 1 ,int(L[i]))
[["+", 0, 656, 0, 14, 8, 196, 0, 299, 0, 636], ["+", 0, 656, 0, 14, 8, 196, 0, 299, 0, 22]]
5
133
16
N= int(input()) E = [input().split()[2:] for _ in range(N)] Q = [0] L = [0] + [-1]*N flag = [1] + [0]*N def func(ide): global Q for i in E[ide]: i = int(i) - 1 if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i) while Q:top = Q.pop(0);func(top) for i in range(N):print(i + 1 ,int(L[i...
N= int(input()) E = [input().split()[2:] for _ in range(N)] Q = [0] L = [0] + [-1]*N frag = [1] + [0]*N def func(ide): global Q for i in E[ide]: i = int(i) - 1 if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i) while Q:top = Q.pop(0);func(top) for i in range(N):print(i + 1 ,int(L[i...
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22]]
5
153
14
N= int(input()) E = [input().split()[2:] for _ in range(N)] Q = [0] L = [0] + [-1]*N frag = [1] + [0]*N def func(ide): global Q for i in E[ide]: i = int(i) - 1 if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i) else:return while Q:top = Q[0];func(top);del Q[0] for i in range(N):...
N= int(input()) E = [input().split()[2:] for _ in range(N)] Q = [0] L = [0] + [-1]*N frag = [1] + [0]*N def func(ide): global Q for i in E[ide]: i = int(i) - 1 if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i) while Q:top = Q[0];func(top);del Q[0] for i in range(N):print(...
[["-", 0, 7, 8, 196, 0, 57, 75, 76, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 76, 0, 102], ["-", 0, 57, 75, 76, 8, 196, 0, 37, 0, 38]]
5
160
3
from queue import Queue n = int(input()) A = [[0 for i in range(n)] for j in range(n)] d = [-1 for i in range(n)] for i in range(n): u, k, *v = list(map(int, input().split())) for j in v: A[int(u)-1][int(j)-1] = 1 q = Queue() q.put(0) d[0] = 0 while not q.empty(): u = q.get() # print('visite...
from queue import Queue n = int(input()) A = [[0 for i in range(n)] for j in range(n)] d = [-1 for i in range(n)] for i in range(n): u, k, *v = list(map(int, input().split())) for j in v: A[int(u)-1][int(j)-1] = 1 q = Queue() q.put(0) d[0] = 0 while not q.empty(): u = q.get() # print('visite...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
196
11
from collections import deque n = int(input()) graph = [[] for _ in range(n)] global Q, S, T global visited, dis Q = deque([0]) S = [0] #訪れた順 T = [] visited = [0 for _ in range(n)] dis = [-1 for _ in range(n)] #初めからの距離 dis[0] = 0 def input_graph(n): for _ in range(n): node_id, num, *v = list(map(int, input().spli...
from collections import deque n = int(input()) graph = [[] for _ in range(n)] global Q, S, T global visited, dis Q = deque([0]) S = [0] #訪れた順 T = [] visited = [0 for _ in range(n)] dis = [-1 for _ in range(n)] #初めからの距離 visited[0] = 1 dis[0] = 0 def input_graph(n): for _ in range(n): node_id, num, *v = list(map(in...
[["+", 0, 656, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 0, 70], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 206, 612], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612]]
5
244
6