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
from collections import deque N, M = map(int, input().split()) road = [[] for _ in range(M+1)] ans = [-1]*(N+1) d = deque() for i in range(M): A, B = map(int, input().split()) road[A].append(B) road[B].append(A) d.append(1) while len(d) != 0: look = d.popleft() for i in road[look]: if ans[i]...
from collections import deque N, M = map(int, input().split()) road = [[] for _ in range(N+1)] ans = [-1]*(N+1) d = deque() for i in range(M): A, B = map(int, input().split()) road[A].append(B) road[B].append(A) d.append(1) while len(d) != 0: look = d.popleft() for i in road[look]: if ans[i]...
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22]]
5
169
from collections import deque n,m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) a,b = a-1,b-1 g[a].append(b) g[b].append(a) stack = deque([0]) dist = [-1] * n dist[0] = 0 while stack: v = stack.popleft() for nv in g[v]: if dis...
from collections import deque n,m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a,b = map(int, input().split()) a,b = a-1, b-1 g[a].append(b) g[b].append(a) stack = deque([0]) dist = [-1]*n dist[0] = 0 while stack: v = stack.popleft() for nv in g[v]: if dist[nv] == -1: ...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
170
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--) #define rrep(i, n) RREP(i, n - 1, 0) #define all(v) v.begin(), v.end() ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--) #define rrep(i, n) RREP(i, n - 1, 0) #define all(v) v.begin(), v.end() ...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
376
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<int, int> Pi; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define fi first #define se second #define endl "\n" template <typename T> inline b...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<int, int> Pi; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define fi first #define se second #define endl "\n" template <typename T> inline b...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
869
import queue n, m = map(int, input().split()) maze = [[] for _ in range(m)] for i in range(m): a, b = map(int, input().split()) maze[a-1].append(b-1) maze[b-1].append(a-1) ans = [-1 for _ in range(n)] ans[0] = 0 q = queue.Queue() q.put(0) while not q.empty(): start = q.get() for end in maze[start]...
import queue n, m = map(int, input().split()) maze = [[] for _ in range(n)] for i in range(m): a, b = map(int, input().split()) maze[a-1].append(b-1) maze[b-1].append(a-1) ans = [-1 for _ in range(n)] ans[0] = 0 q = queue.Queue() q.put(0) while not q.empty(): start = q.get() for end in maze[start]...
[["-", 12, 658, 0, 659, 12, 652, 3, 4, 0, 22], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 22]]
5
200
from collections import deque n, m = map(int, input().split()) a = [0] * (m + 1) b = [0] * (m + 1) road = [[] for _ in range(m + 1)] for i in range(m): a[i], b[i] = map(int, input().split()) road[a[i]].append(b[i]) road[b[i]].append(a[i]) ans = [-1] * (n + 1) ans[0] = 0 ans[1] = 0 q = deque() q.appendle...
from collections import deque n, m = map(int, input().split()) a = [0] * (m + 1) b = [0] * (m + 1) road = [[] for _ in range(n + 1)] for i in range(m): a[i], b[i] = map(int, input().split()) road[a[i]].append(b[i]) road[b[i]].append(a[i]) ans = [-1] * (n + 1) ans[0] = 0 ans[1] = 0 q = deque() q.appendle...
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22]]
5
237
from collections import deque n,m = map(int,input().split()) ab=[[] for _ in range(n+1)] for _ in range(m): a,b=map(int,input().split()) ab[a].append(b) ab[b].append(a) ans=[0]*(n+1) ans[1]=1 que=deque() que.append(1) while que: x=que.popleft() for i in ab[x]: if ans[i]==0: ans[...
from collections import deque n,m = map(int,input().split()) ab=[[] for _ in range(n+1)] for _ in range(m): a,b=map(int,input().split()) ab[a].append(b) ab[b].append(a) ans=[0]*(n+1) ans[1]=1 que=deque() que.append(1) while que: x=que.popleft() for i in ab[x]: if ans[i]==0: ans[...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
168
#include "bits/stdc++.h" using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > ...
#include "bits/stdc++.h" using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > ...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
854
import queue n,m = map(int,input().split()) hen = [[] for i in range(m)] ans = [0 for i in range(n)] a,b = 0,0 for i in range(m): a,b = map(int,input().split()) hen[a-1].append(b) hen[b-1].append(a) q = queue.Queue() q.put(1) while q.empty() == False: head = q.get() for h in hen[head-1]: ...
import queue n,m = map(int,input().split()) hen = [[] for i in range(n)] ans = [0 for i in range(n)] a,b = 0,0 for i in range(m): a,b = map(int,input().split()) hen[a-1].append(b) hen[b-1].append(a) q = queue.Queue() q.put(1) while q.empty() == False: head = q.get() for h in hen[head-1]: ...
[["-", 12, 658, 0, 659, 12, 652, 3, 4, 0, 22], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 22]]
5
227
#! /usr/bin/env python3 # from math import gcd from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate,...
#! /usr/bin/env python3 # from math import gcd from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate,...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
265
/* ID: rchalam1 LANG: C++11 TASK: */ // For train.usaco.org, fill the template above. // Competitive Coding Template // GCC OPTIMIAZTION FLAGS #ifndef LOCAL #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC targe...
/* ID: rchalam1 LANG: C++11 TASK: */ // For train.usaco.org, fill the template above. // Competitive Coding Template // GCC OPTIMIAZTION FLAGS #ifndef LOCAL #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC targe...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 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, 5, 0, 6]]
1
2,392
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define vll vector<ll> #define vvll vector<vll> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vb vector<bool> #define pii pair<int, int> #define vpli vector<pair<long long, int>> #de...
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define vll vector<ll> #define vvll vector<vll> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vb vector<bool> #define pii pair<int, int> #define vpli vector<pair<long long, int>> #d...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
508
#include <iostream> #include <queue> #include <vector> int main(void) { int n, m, a, b; std::cin >> n >> m; std::vector<int> c(n + 1), d(n + 1); std::vector<std::vector<int>> r; r.resize(n + 1); std::queue<int> q; for (int i = 0; i < m; i++) { std::cin >> a >> b; r[a].push_back(b); r[b].push...
#include <iostream> #include <queue> #include <vector> int main(void) { int n, m, a, b; std::cin >> n >> m; std::vector<int> c(n + 1), d(n + 1); std::vector<std::vector<int>> r; r.resize(n + 1); std::queue<int> q; for (int i = 0; i < m; i++) { std::cin >> a >> b; r[a].push_back(b); r[b].push...
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
334
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define codefor \ int test; \ scanf("...
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define codefor \ int test; \ scanf("...
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
832
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque n,m = [int(x) for x in stdin.readline().rstrip().split()] d = {} for i in range(n): a,b = [int(x) for x in stdin.readline().rstrip().split()] if a not in d: d[a] =...
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque n,m = [int(x) for x in stdin.readline().rstrip().split()] d = {} for i in range(m): a,b = [int(x) for x in stdin.readline().rstrip().split()] if a not in d: d[a] =...
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22]]
5
228
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) ls = deque([0]) ans = [-1] * N ans[0] = 0 while len(ls) > 0: v = ls.pop() for next_v in G[v]: if ans[next_v]...
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) ls = deque([0]) ans = [-1] * N ans[0] = 0 while len(ls) > 0: v = ls.popleft() for next_v in G[v]: if ans[nex...
[["-", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22]]
5
189
#include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef ...
#include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef ...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
336
#!/usr/bin/env python3 from collections import deque import sys input = sys.std.readline n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) que = deque() dist = [float('inf')] * n prev = ...
#!/usr/bin/env python3 from collections import deque import sys input = sys.stdin.readline n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) que = deque() dist = [float('inf')] * n prev ...
[["-", 0, 1, 0, 662, 12, 319, 500, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 319, 500, 319, 319, 22]]
5
209
import sys, bisect, math, itertools, string, queue, copy # import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+...
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from math import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 d...
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["-", 36, 36, 0, 656, 0, 686, 687, 673, 0, 22], ["+", 36, 36, 0, 656, 0, 686, 687, 673, 0, 22]]
5
423
from collections import deque n,m=map(int,input().split()) node=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) node[b-1].append(a-1) node[a-1].append(b-1) distance=[-1]*n distance[0]=0 d=deque() d.append(0) while d: v=d.popleft() for i in node[v]: if distance[i]!=-1:...
from collections import deque n,m=map(int,input().split()) node=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) node[b-1].append(a-1) node[a-1].append(b-1) distance=[-1]*n distance[0]=0 d=deque() d.append(0) while d: v=d.popleft() for i in node[v]: if distance[i]!=-1:...
[["-", 0, 1, 0, 662, 12, 657, 31, 206, 51, 22], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 70], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 73]]
5
176
from collections import deque N, M = map(int, input().split()) ARR = [] for i in range(N): ARR.append(list(map(int, input().split()))) def prepare(n, m, arr): nodes = [[] for i in range(n)] nodeStatus = [False for i in range(n)] for i in range(n): startNode = arr[i][0] - 1 endNode = ...
from collections import deque N, M = map(int, input().split()) ARR = [] for i in range(M): ARR.append(list(map(int, input().split()))) def prepare(n, m, arr): nodes = [[] for i in range(n)] nodeStatus = [False for i in range(n)] for i in range(m): startNode = arr[i][0] - 1 endNode = ...
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 22]]
5
303
N, M = 6, 9 ARR = [ [3, 4], [6, 1], [2, 4], [5, 3], [4, 6], [1, 5], [6, 2], [4, 5], [5, 6], ] N,M = 4, 4 ARR = [ [1, 2], [2, 3], [3, 4], [4, 2], ] N, M = map(int, input().split()) ARR = [] for i in range(M): ARR.append(list(map(int, input().split()))) from c...
N, M = 6, 9 ARR = [ [3, 4], [6, 1], [2, 4], [5, 3], [4, 6], [1, 5], [6, 2], [4, 5], [5, 6], ] N, M = 4, 4 ARR = [ [1, 2], [2, 3], [3, 4], [4, 2], ] N, M = map(int, input().split()) ARR = [] for i in range(M): ARR.append(list(map(int, input().split()))) from co...
[["+", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
416
#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair<int, int>; #define PI acos(-1) #define Rep(i, n) for (int i = 0; i < (int)(n); i++) #define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++) #define All(vec) vec.begin(), vec.end() #define Sum(vec) accumulate(vec.begin(), vec.end(), ...
#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair<int, int>; #define PI acos(-1) #define Rep(i, n) for (int i = 0; i < (int)(n); i++) #define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++) #define All(vec) vec.begin(), vec.end() #define Sum(vec) accumulate(vec.begin(), vec.end(), ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
355
#import time from itertools import dropwhile, takewhile def main(): N, M = list(map(int, input().split())) lis = [list(map(int, input().split())) for _ in range(M)] #print(lis) edge = [[] for _ in range(N+1)] #print(edge) for a,b in lis: edge[a].append(b) edge[b].append(a) ...
#import time from itertools import dropwhile, takewhile def main(): N, M = list(map(int, input().split())) lis = [list(map(int, input().split())) for _ in range(M)] #print(lis) edge = [[] for _ in range(N+1)] #print(edge) for a,b in lis: edge[a].append(b) edge[b].append(a) ...
[["-", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
195
from collections import deque n,m=map(int,input().split()) adj=[[] for _ in range(n)] for _ in range(m): a,b =map(int,input().split()) a-=1 b-=1 adj[a].append(b) adj[b].append(a) ans=[0]*n que=deque([]) que.append(0) while que: e=que.popleft for i in adj[e]: if ans[i]!=0: continue ans[i]=e+1...
from collections import deque n,m=map(int,input().split()) adj=[[] for _ in range(n)] for _ in range(m): a,b =map(int,input().split()) a-=1 b-=1 adj[a].append(b) adj[b].append(a) ans=[0]*n que=deque([]) que.append(0) while que: e=que.popleft() for i in adj[e]: if ans[i]!=0: continue ans[i]=e...
[["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
163
N, M = map(int, input().split()) nextroom = [[] for _ in range(N)] for _ in range(M): A, B = map(int, input().split()) nextroom[A-1].append(B-1) nextroom[B-1].append(A-1) sgn = [-1 for _ in range(N)] sgn[0] = 0 depth = [float('inf') for _ in range(N)] depth[0] = 0 now = [0] nextvisit = [] for j in range(1, M):...
N, M = map(int, input().split()) nextroom = [[] for _ in range(N)] for _ in range(M): A, B = map(int, input().split()) nextroom[A-1].append(B-1) nextroom[B-1].append(A-1) sgn = [-1 for _ in range(N)] sgn[0] = 0 depth = [float('inf') for _ in range(N)] depth[0] = 0 now = [0] nextvisit = [] for j in range(1, M+1...
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
231
#include <bits/stdc++.h> using namespace std; int main() { int x, y, nodes, edges; cin >> nodes >> edges; nodes++; vector<int> v[nodes]; for (int i = 0; i < edges; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } int s = 1, vis[nodes] = {0}, level[nodes] = {0}; queue<int> q; ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, nodes, edges; cin >> nodes >> edges; nodes++; vector<int> v[nodes]; for (int i = 0; i < edges; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } int s = 1, vis[nodes] = {0}, level[nodes] = {0}; queue<int> q; ...
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
322
#include <bits/stdc++.h> using namespace std; void bfs(vector<vector<int>> &G, vector<int> &dist, vector<int> &prev, int start) { dist[start] = 0; queue<int> q; q.push(start); while (!q.empty()) { int v = q.front(); q.pop(); for (int next_v : G[v]) { if (dist[next_v] != -1) c...
#include <bits/stdc++.h> using namespace std; void bfs(vector<vector<int>> &G, vector<int> &dist, vector<int> &prev, int start) { dist[start] = 0; queue<int> q; q.push(start); while (!q.empty()) { int v = q.front(); q.pop(); for (int next_v : G[v]) { if (dist[next_v] != -1) c...
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78]]
1
277
from collections import deque def bfs(graph, visited, ss): queue = deque([ss]) visited[ss] = 0 ans = [0]*n while queue: s = queue.popleft() for new_s in graph[s] : if visited[new_s] == -1: # 移動回数の計算 visited[new_s] = visited[s] + 1 queue.append(new_s) ans[new_s] = s...
from collections import deque def bfs(graph, visited, ss): queue = deque([ss]) visited[ss] = 0 ans = [0]*n while queue: s = queue.popleft() for new_s in graph[s] : if visited[new_s] == -1: # 移動回数の計算 visited[new_s] = visited[s] + 1 queue.append(new_s) ans[new_s] = s...
[["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
204
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); String[] cmd = s.split(" "); int n = Integer.v...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); String[] cmd = s.split(" "); int n = Integer.v...
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
418
#include <bits/stdc++.h> using namespace std; #define f(i, a, b) for (int i = a; i < b; i++) #define fll(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (int i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define vvi ...
#include <bits/stdc++.h> using namespace std; #define f(i, a, b) for (int i = a; i < b; i++) #define fll(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (int i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define vvi ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
464
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int hint[n]; vector<int> arc[m]; for (int i = 0; i < n; i++) hint[i] = -1; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; arc[a].push_back(b); arc[b].push_back(a); } queue<...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int hint[n]; vector<int> arc[m + 10]; for (int i = 0; i < n; i++) hint[i] = -1; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; arc[a].push_back(b); arc[b].push_back(a); } ...
[["+", 8, 9, 0, 43, 49, 80, 81, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 80, 81, 16, 12, 13]]
1
245
Copy Copy n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _i in range(m)] visit = [-1 for _ in range(n)] visit[0] = 0 tree = [[] for _ in range(n)] for a, b in ab: tree[a-1].append(b-1) tree[b-1].append(a-1) from collections import deque q = deque([0]) while q: p = q.popleft(...
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _i in range(m)] visit = [-1 for _ in range(n)] visit[0] = 0 tree = [[] for _ in range(n)] for a, b in ab: tree[a-1].append(b-1) tree[b-1].append(a-1) from collections import deque q = deque([0]) while q: p = q.popleft() for i...
[["-", 36, 36, 36, 36, 0, 656, 0, 1, 0, 22]]
5
200
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a =...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a =...
[["+", 8, 9, 0, 43, 49, 53, 54, 55, 0, 24], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 43, 49, 53, 54, 55, 0, 25]]
1
367
# -*- codinf: utf-8 -*- from collections import deque N, M = map(int, input().split()) route = [[] for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) route[a].append(b) route[b].append(a) q = deque([1]) # 頂点を設定して初期化 pre = [None] * (N+1) # 頂点までの最短に進む時の次の頂点のリスト pre[1] = 0 # 頂点は0 depth =...
# -*- codinf: utf-8 -*- from collections import deque N, M = map(int, input().split()) route = [[] for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) route[a].append(b) route[b].append(a) q = deque([1]) # 頂点を設定して初期化 pre = [None] * (N+1) # 頂点までの最短に進む時の次の頂点のリスト pre[1] = 0 # 頂点は0 depth =...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
205
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long...
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long...
[["-", 0, 16, 31, 16, 31, 2, 3, 4, 0, 22], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 22]]
1
2,618
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #...
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #...
[["-", 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, 16, 31, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
501
import sys # import math import heapq # input = sys.stdin.readline from collections import deque def main(): n, m = map(int,input().split()) room =[[]for _ in range(n+1)] for i in range(m): a,b = map(int,input().split()) room[a].append(b) room[b].append(a) point = [0] *(n+1)...
import sys # import math import heapq # input = sys.stdin.readline from collections import deque def main(): n, m = map(int,input().split()) room =[[]for _ in range(n+1)] for i in range(m): a,b = map(int,input().split()) room[a].append(b) room[b].append(a) point = [0] *(n+1)...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 0, 652, 63, 319, 500, 557, 0, 6, 0, 44]]
5
204
N,M = gets.split.map &:to_i AB = M.times.map{ gets.split.map &:to_i} Map = Array.new(M+1).map{[]} AB.each do |a,b| Map[a] << b Map[b] << a end ans = [nil]*(N+1) qry = Map[1].map{|i| [i,1]} while q = qry.shift to,from = q next if ans[to] ans[to] = from Map[to].each{|i| qry << [i,to]} end if an...
N,M = gets.split.map &:to_i AB = M.times.map{ gets.split.map &:to_i} Map = Array.new(N+1).map{[]} AB.each do |a,b| Map[a] << b Map[b] << a end ans = [nil]*(N+1) qry = Map[1].map{|i| [i,1]} while q = qry.shift to,from = q next if ans[to] ans[to] = from Map[to].each{|i| qry << [i,to]} end if an...
[["-", 12, 652, 486, 652, 3, 4, 0, 738, 31, 743], ["+", 12, 652, 486, 652, 3, 4, 0, 738, 31, 743]]
4
171
from collections import deque q=deque() def MI(): return map(int, input().split()) N,M=MI() g=[[] for _ in range(M+1)] for _ in range(M): a,b=MI() g[a].append(b) g[b].append(a) check=[0]*(N+1) check[1]=1 ans=[0]*(N+1) q.append(1) while len(q)>0: v=q.popleft() for u in g[v]: if check[u]==0: check[u]=...
from collections import deque q=deque() def MI(): return map(int, input().split()) N,M=MI() g=[[] for _ in range(N+1)] for _ in range(M): a,b=MI() g[a].append(b) g[b].append(a) check=[0]*(N+1) check[1]=1 ans=[0]*(N+1) q.append(1) while len(q)>0: v=q.popleft() for u in g[v]: if check[u]==0: check[u]=...
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22]]
5
190
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __...
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __...
[["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
332
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N, M = map(int, input().split()) AB = [map(int, input().split()) for _ in range(M)] C = [[] for _ in range(N+1)] for a, b in AB: C[a].append(b) C[b].append(a) ...
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N, M = map(int, input().split()) AB = [map(int, input().split()) for _ in range(M)] C = [[] for _ in range(N+1)] for a, b in AB: C[a].append(b) C[b].append(a) ...
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
197
#ABC168D def main(): import sys from collections import defaultdict from collections import deque N, M = map(int, sys.stdin.readline().split()) AB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] #print(AB) edge = defaultdict(list) for ab in AB: edge[ab[0]...
#ABC168D def main(): import sys from collections import defaultdict from collections import deque N, M = map(int, sys.stdin.readline().split()) AB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] #print(AB) edge = defaultdict(list) for ab in AB: edge[ab[0]...
[["+", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
221
from collections import deque n,m=map(int,input().split()) ans=[0]*(n+1) adj=[[] for _ in range(n+1)] for i in range(m): u,v=map(int,input().split()) adj[u].append(v) adj[v].append(u) que=deque([1]) vis=[0 for _ in range(n+1)] vis[1]=1 while que: t=que.popleft() #print(t) for i in adj[t]: ...
from collections import deque n,m=map(int,input().split()) ans=[0]*(n+1) adj=[[] for _ in range(n+1)] for i in range(m): u,v=map(int,input().split()) adj[u].append(v) adj[v].append(u) que=deque([1]) vis=[0 for _ in range(n+1)] vis[1]=1 while que: t=que.popleft() #print(t) for i in adj[t]: ...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
199
#include <algorithm> #include <iostream> #include <queue> #include <string> #include <utility> #include <vector> #define iter(n) for (int iter_var = 0; iter_var < n; iter_var += 1) #define rep(i, s, n) for (int i = s; i < n; i += 1) #define lli long long int #define INF 1e9 #define MOD 1000000007 using namespace std;...
#include <algorithm> #include <iostream> #include <queue> #include <string> #include <utility> #include <vector> #define iter(n) for (int iter_var = 0; iter_var < n; iter_var += 1) #define rep(i, s, n) for (int i = s; i < n; i += 1) #define lli long long int #define INF 1e9 #define MOD 1000000007 using namespace std;...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
271
import queue N,M=map(int,input().split()) adj=[[] for s in range(M+1)] parent=[-1]*(N+1) for i in range(M): A,B=map(int,input().split()) adj[A].append(B) adj[B].append(A) q=queue.Queue() q.put((1,0)) while(not q.empty()): x,p=q.get() if parent[x]!=-1: continue parent[x]=p for next in...
import queue N,M=map(int,input().split()) adj=[[] for s in range(N+1)] parent=[-1]*(N+1) for i in range(M): A,B=map(int,input().split()) adj[A].append(B) adj[B].append(A) q=queue.Queue() q.put((1,0)) while(not q.empty()): x,p=q.get() if parent[x]!=-1: continue parent[x]=p for next in...
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22]]
5
185
#!/usr/bin/env python3 from collections import deque q = deque([0]) Dequeue = lambda: q.popleft() Enqueue = lambda x: q.append(x) n, m = map(int, input().split()) l = [[] for _ in [0]*n] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 l[a] += [b] l[b] += [a] ans = [-1]*n while q: ...
#!/usr/bin/env python3 from collections import deque q = deque([0]) Dequeue = lambda: q.popleft() Enqueue = lambda x: q.append(x) n, m = map(int, input().split()) l = [[] for _ in [0]*n] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 l[a] += [b] l[b] += [a] ans = [-1]*n while q: ...
[["-", 0, 57, 64, 196, 0, 1, 0, 677, 17, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32]]
5
186
#include <bits/stdc++.h> using namespace std; #define itn int #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) x.begin(), x.end() #define pb push_back #define mb make_pair #define fi first #define se second typedef vector<int> vi; typedef long long ll; typedef pair<int, int> pii; const ll mod = 100000...
#include <bits/stdc++.h> using namespace std; #define itn int #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) x.begin(), x.end() #define pb push_back #define mb make_pair #define fi first #define se second typedef vector<int> vi; typedef long long ll; typedef pair<int, int> pii; const ll mod = 100000...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73]]
1
364
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 3); vector<int> p(n + 3), vis(n + 3, 0); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } int r = 1; queue<int> q; q.push(1); v...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 3); vector<int> p(n + 3), vis(n + 3, 0); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } int r = 1; queue<int> q; q.push(1); v...
[["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
257
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define MP make_pair #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORR(x, arr) for (auto &x : arr) #define PII pair<int, int> #define FI first #define SE second ...
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define MP make_pair #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORR(x, arr) for (auto &x : arr) #define PII pair<int, int> #define FI first #define SE second ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
408
#include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) vector<int> to[100005]; const int INF = 1001001001; int main() { int n, m; cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; --a; --b; to[a].push_back(b); to[b].p...
#include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) vector<int> to[100005]; const int INF = 1001001001; int main() { int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; --a; --b; to[a].push_back(b); to[b].p...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
256
from collections import deque n, m = map(int, input().split()) table = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) table[a].append(b) table[b].append(a) ans = [0] * (n + 1) ans[1] = -1 queue = deque() for s in table[1]: ans[s] = 1 # 注目してるノード番号, ひとつ前の番号 queue.a...
from collections import deque n, m = map(int, input().split()) table = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) table[a].append(b) table[b].append(a) ans = [0] * (n + 1) ans[1] = -1 queue = deque() for s in table[1]: ans[s] = 1 # 注目してるノード番号, ひとつ前の番号 queue.a...
[["+", 75, 76, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
216
from collections import deque dic={} n,m=map(int,input().split()) nod=[[]] keep=[0]*n for i in range(n-1): nod.append([]) for i in range(m): a,b=map(int,input().split()) nod[a-1].append(b) nod[b-1].append(a) use=deque() use.append(1) for i in range(0,10**100): if bool(use): sss=use.popleft() for j in ...
from collections import deque dic={} n,m=map(int,input().split()) nod=[[]] keep=[0]*n for i in range(n-1): nod.append([]) for i in range(m): a,b=map(int,input().split()) nod[a-1].append(b) nod[b-1].append(a) use=deque() use.append(1) for i in range(0,10**100): if bool(use): sss=use.popleft() for j in ...
[["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
190
#include <bits/stdc++.h> #define ll long long #define fr(i, p, n) for (ll i = p; i < n; i++) #define fr1(i, p, n) for (ll i = p; i >= n; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #include <stdio.h> #define PI 3.14159265358979323846 #define MOD 1000000007 #define INF 1e9 #define p...
#include <bits/stdc++.h> #define ll long long #define fr(i, p, n) for (ll i = p; i < n; i++) #define fr1(i, p, n) for (ll i = p; i >= n; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #include <stdio.h> #define PI 3.14159265358979323846 #define MOD 1000000007 #define INF 1e9 #define p...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
323
from collections import deque n, m = map(int, input().split()) ab = [[] for i in range(n+1)] for i in range(m): a, b = map(int, input().split()) ab[a].append(b) ab[b].append(a) ans = [-1]*(n+1) que = deque([1]) while que: q = que.popleft() for i in ab[q]: if ans[i] == -1: que....
from collections import deque n, m = map(int, input().split()) ab = [[] for i in range(n+1)] for i in range(m): a, b = map(int,input().split()) ab[a].append(b) ab[b].append(a) ans = [-1]*(n+1) que = deque([1]) while que: q = que.popleft() for i in ab[q]: if ans[i] == -1: que.append(i) ans[i...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
161
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
424
import queue N, M = map(int, input().split()) adj = [[] for i in [0]*N] # 隣接リスト for i in [0]*M: a, b = map(int, input().split()) adj[a-1].append(b) adj[b-1].append(a) print(adj) que = queue.Queue() que.put(1) guide = [-1]*(N) while not que.empty(): x = que.get() for y in adj[x-1]: if gui...
import queue N, M = map(int, input().split()) adj = [[] for i in [0]*N] # 隣接リスト for i in [0]*M: a, b = map(int, input().split()) adj[a-1].append(b) adj[b-1].append(a) que = queue.Queue() que.put(1) guide = [-1]*(N) while not que.empty(): x = que.get() for y in adj[x-1]: if guide[y-1] == ...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
176
#include <bits/stdc++.h> using namespace std; int N, M; vector<vector<int>> adjList(100100); bool visited[100100]; int dist[100100]; int vcnt; void bfs() { vcnt = 1; queue<int> q; q.push(1); dist[1] = 0; visited[1] = true; while (!q.empty()) { int here = q.front(); q.pop(); for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; int N, M; vector<vector<int>> adjList(100100); bool visited[100100]; int dist[100100]; int vcnt; void bfs() { vcnt = 1; queue<int> q; q.push(1); dist[1] = 0; visited[1] = true; while (!q.empty()) { int here = q.front(); q.pop(); for (int i = 0; ...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
333
import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); List<List<Integer>> edge = n...
import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); List<List<Integer>> edge = n...
[["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
3
338
from collections import deque n,m = map(int, input().split()) dic = {} for i in range(m): a,b = map(int,input().split()) dic.setdefault(a,[]) dic.setdefault(b,[]) dic[a].append(b) dic[b].append(a) array = [-1] * (n+1) d = deque() d.append(1) while len(d) != 0: tmp = d.popleft() arr = dic.get(tmp...
from collections import deque n,m = map(int, input().split()) dic = {} for i in range(m): a,b = map(int,input().split()) dic.setdefault(a,[]) dic.setdefault(b,[]) dic[a].append(b) dic[b].append(a) array = [-1] * (n+1) d = deque() d.append(1) while len(d) != 0: tmp = d.popleft() arr = dic.get(tmp...
[["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
178
import java.io.*; import java.util.*; public class Main { static ArrayList<Integer> edge[]; public static void dfs(int src, boolean vis[], TreeSet<Integer> ts) { vis[src] = true; ts.add(src); for (int i = 0; i < edge[src].size(); i++) { int temp = edge[src].get(i); if (!vis[temp]) df...
import java.io.*; import java.util.*; public class Main { static ArrayList<Integer> edge[]; public static void dfs(int src, boolean vis[], TreeSet<Integer> ts) { vis[src] = true; ts.add(src); for (int i = 0; i < edge[src].size(); i++) { int temp = edge[src].get(i); if (!vis[temp]) df...
[["-", 0, 1, 0, 11, 12, 16, 31, 504, 516, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 504, 0, 70], ["-", 0, 1, 0, 11, 12, 16, 31, 504, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 499]]
3
572
#include <bits/stdc++.h> #define pii pair<int, int> #define fi first #define pb push_back #define si second #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ...
#include <bits/stdc++.h> #define pii pair<int, int> #define fi first #define pb push_back #define si second #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ...
[["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6]]
1
277
from collections import deque N, M=map(int, sys.stdin.readline().split()) p = [] for i in range(M): p.append(list(map(int, sys.stdin.readline().split()))) graph = [[] for _ in range(N + 1)] for pi in p: graph[pi[0]].append(pi[1]) graph[pi[1]].append(pi[0]) q = deque([1]) p = [0] * (N + 1) p[1] = 1 while ...
import sys from collections import deque N, M=map(int, sys.stdin.readline().split()) p = [] for i in range(M): p.append(list(map(int, sys.stdin.readline().split()))) graph = [[] for _ in range(N + 1)] for pi in p: graph[pi[0]].append(pi[1]) graph[pi[1]].append(pi[0]) q = deque([1]) p = [0] * (N + 1) p[1]...
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
5
209
roomNum, aisleNum = map(int, input().split()) aisles = [ list(map(int, input().split())) for _ in range(aisleNum) ] aisleTree = [ [] for _ in range(aisleNum+1) ] for roomA, roomB in aisles: aisleTree[roomA].append(roomB) aisleTree[roomB].append(roomA) from collections import deque que = deque() distanceFrom...
roomNum, aisleNum = map(int, input().split()) aisles = [ list(map(int, input().split())) for _ in range(aisleNum) ] aisleTree = [ [] for _ in range(roomNum+1) ] for roomA, roomB in aisles: aisleTree[roomA].append(roomB) aisleTree[roomB].append(roomA) from collections import deque que = deque() distanceFromR...
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 31, 22]]
5
216
#include <bits/stdc++.h> using namespace std; vector<int> g[200005], parent(200005, -1); vector<bool> vis(200005, false); int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } parent[1] = 0; vis[1] = true; ...
#include <bits/stdc++.h> using namespace std; vector<int> g[200005], parent(200005, -1); vector<bool> vis(200005, false); int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } parent[1] = 0; vis[1] = true; ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
276
#include <bits/stdc++.h> using namespace std; vector<int> findShortestPath(int N, int M, vector<vector<int>> &neighbors) { vector<bool> visited(N, false); queue<int> q; vector<int> parent(N, -1); q.emplace(0); visited[0] = true; while (!q.empty()) { int curr = q.front(); q.pop(); for (int nei ...
#include <bits/stdc++.h> using namespace std; vector<int> findShortestPath(int N, int M, vector<vector<int>> &neighbors) { vector<bool> visited(N, false); queue<int> q; vector<int> parent(N, -1); q.emplace(0); visited[0] = true; while (!q.empty()) { int curr = q.front(); q.pop(); for (int nei ...
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
340
from collections import deque n, m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) g[a-1].append(b-1) g[b-1].append(a-1) queue = deque([0]) d = [None]*n d[0] = 0 while queue: v = queue.popleft() for i in g[v]: if d[i] == Non...
from collections import deque n, m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) g[a-1].append(b-1) g[b-1].append(a-1) queue = deque([0]) d = [None]*n d[0] = 0 while queue: v = queue.popleft() for i in g[v]: if d[i] == No...
[["-", 0, 1, 0, 662, 12, 657, 31, 206, 51, 22], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 70], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 73]]
5
189
N, M = map(int, input().split()) node =[[] for _ in range(N)] for _ in range(M): x, y = map(int, input().split()) node[x-1].append(y-1) node[y-1].append(x-1) ct = [-1]*N i = 0 stack = [] ct[0] = 0 stack.append(0) while len(stack) != 0: v = stack.pop() for e in node[v]: if ct[e] == -1: ct[e] = v ...
N, M = map(int, input().split()) node =[[] for _ in range(N)] for _ in range(M): x, y = map(int, input().split()) node[x-1].append(y-1) node[y-1].append(x-1) ct = [-1]*N i = 0 stack = [] ct[0] = 0 stack.append(0) while len(stack) != 0: v = stack.pop(0) for e in node[v]: if ct[e] == -1: ct[e] = v ...
[["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 612]]
5
175
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { int n, m; cin >> n >> m; int a, b; vector<int> to[10005]; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } queue<int> q; vector<int> dist(n, INF); ...
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { int n, m; cin >> n >> m; int a, b; vector<int> to[100005]; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } queue<int> q; vector<int> dist(n, INF); ...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 52, 15, 339, 51, 91, 28, 23, 0, 24], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 0, 35], ["+", 0, 7, 8, 9,...
1
261
#include <bits/stdc++.h> #define ll long long #define db double using namespace std; typedef pair<int, int> P; const int M = 1e5 + 10; int n, m, dis[M]; vector<int> G[M]; int main() { scanf("%d%d", &n, &m); for (int i = 0, x, y; i < m; i++) { scanf("%d%d", &x, &y); G[x].push_back(y); G[y].push_back(x); ...
#include <bits/stdc++.h> #define ll long long #define db double using namespace std; typedef pair<int, int> P; const int M = 1e5 + 10; int n, m, dis[M]; vector<int> G[M]; int main() { scanf("%d%d", &n, &m); for (int i = 0, x, y; i < m; i++) { scanf("%d%d", &x, &y); G[x].push_back(y); G[y].push_back(x); ...
[["-", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
1
316
#include <bits/stdc++.h> using namespace std; // SHORTCUTS #define ll long long #define endl '\n' #define i1(a) cin >> a #define i2(a, b) cin >> a >> b #define i3(a, b, c) cin >> a >> b >> c #define o1(a) cout << a << endl #define o2(a, b) cout << a << " " << b << endl #define o3(a, b, c) cout << a << " " << b << " "...
#include <bits/stdc++.h> using namespace std; // SHORTCUTS #define ll long long #define endl '\n' #define i1(a) cin >> a #define i2(a, b) cin >> a >> b #define i3(a, b, c) cin >> a >> b >> c #define o1(a) cout << a << endl #define o2(a, b) cout << a << " " << b << endl #define o3(a, b, c) cout << a << " " << b << " "...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
790
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 1); for (int i = 0, u, v; i < m; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } vector<int> d(n + 1, -1), q; q.push_back(1); d[1] = 0; for (int i = 0; i < q.size()...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 1); for (int i = 0, u, v; i < m; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } vector<int> d(n + 1, -1), q; q.push_back(1); d[1] = 0; for (int i = 0; i < q.size()...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
236
from collections import deque n,m = map(int,input().split()) adjacent_list = [[] for i in range(n+1)] for i in range(m): a,b = map(int,input().split()) adjacent_list[a].append(b) adjacent_list[b].append(a)#どこの点がどことつながっているか pre = [-1] * (n+1) dist = [-1] * (n+1) dist[1] = 0 que = deque([1]) while que: ...
from collections import deque n,m = map(int,input().split()) adjacent_list = [[] for i in range(n+1)] for i in range(m): a,b = map(int,input().split()) adjacent_list[a].append(b) adjacent_list[b].append(a)#どこの点がどことつながっているか pre = [-1] * (n+1) dist = [-1] * (n+1) dist[1] = 0 que = deque([1]) while que: ...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22]]
5
193
#include <bits/stdc++.h> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) const int INF = 1001001001; const ll BIG = 1000000007; const double PI = 3.141592653589793; vector<int> to[100005]; int main() { int n, m; c...
#include <bits/stdc++.h> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) const int INF = 1001001001; const ll BIG = 1000000007; const double PI = 3.141592653589793; vector<int> to[100005]; int main() { int n, m; c...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
275
//#include<bits/stdc++.h> // using namespace std; //#define mem(a) memset(a,0,sizeof(a)) //#define dbg(x) cout<<#x<<" = "<<x<<endl //#define ll long long // int d[100010]={0}; // map<int,vector<int> >a; // int n,m; ////int dbg=0; ////void dbve(vector<int>tt) ////{ //// for(vector<int>::iterator it=tt.begin();it!=tt.end...
//#include<bits/stdc++.h> // using namespace std; //#define mem(a) memset(a,0,sizeof(a)) //#define dbg(x) cout<<#x<<" = "<<x<<endl //#define ll long long // int d[100010]={0}; // map<int,vector<int> >a; // int n,m; ////int dbg=0; ////void dbve(vector<int>tt) ////{ //// for(vector<int>::iterator it=tt.begin();it!=tt.end...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
1
351
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; vector<int> to[100005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } queue<int> q; vector<int> dist(n, INF)...
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; vector<int> to[100005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } queue<int> q; vector<int> dist(n, INF)...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
249
#include <iostream> #include <queue> #include <vector> using namespace std; using Graph = vector<vector<int>>; int main(void) { int N, M; cin >> N >> M; Graph G(N); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } vector<in...
#include <iostream> #include <queue> #include <vector> using namespace std; using Graph = vector<vector<int>>; int main(void) { int N, M; cin >> N >> M; Graph G(N); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } vector<in...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
252
#include <iostream> #include <queue> #include <vector> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> dp(n); REP(i, n) { int a, b; cin >> a >> b; a--, b--; dp[a].push_b...
#include <iostream> #include <queue> #include <vector> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> dp(n); REP(i, m) { int a, b; cin >> a >> b; a--, b--; dp[a].push_b...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
265
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a,b = map(int, input().split()) graph[a].append(b) graph[b].append(a) print(graph) dist = [0] * (n + 1) d=deque() d.append(1) while d: v = d.popleft() for i in graph[v]: ...
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a,b = map(int, input().split()) graph[a].append(b) graph[b].append(a) dist = [0] * (n + 1) d=deque() d.append(1) while d: v = d.popleft() for i in graph[v]: if not dis...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
164
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long ...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long ...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
451
#include <bits/stdc++.h> //短縮 #define rep(i, n) for (int i = 0; i < (n); ++i) // sort()用 #define all(v) v.begin(), v.end() #define PB(N) push_back(N) using namespace std; using Graph = vector<vector<int>>; int main() { int N, M; cin >> N >> M; Graph AB(M, vector<int>()); rep(i, M) { int buffer_a, buf...
#include <bits/stdc++.h> //短縮 #define rep(i, n) for (int i = 0; i < (n); ++i) // sort()用 #define all(v) v.begin(), v.end() #define PB(N) push_back(N) using namespace std; using Graph = vector<vector<int>>; int main() { int N, M; cin >> N >> M; Graph AB(M + 10, vector<int>()); rep(i, M) { int buffer_a...
[["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
1
287
/* [Template].cpp Example code to use when starting new code. This particular problem was problem 977A_Wrong_Subtraction from CodeForces Compile: g++ -o D_Double_Dots.exe D_Double_Dots.cpp Execute: ./D_Double_Dots */ #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #i...
/* [Template].cpp Example code to use when starting new code. This particular problem was problem 977A_Wrong_Subtraction from CodeForces Compile: g++ -o D_Double_Dots.exe D_Double_Dots.cpp Execute: ./D_Double_Dots */ #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #i...
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
318
def BFS(K,edges,N): INF = 10**10 roots=[ [] for i in range(N)] for a,b in edges: roots[a-1]+=[b-1] roots[b-1]+=[a-1] dist=[INF]*N pre = [-1]*N stack=[] stack.append(K) dist[K]=0 while stack: label=stack.pop(-1) for i in roots[label]: if dist[i]==INF: dist[i]=dist[label]+1...
def BFS(K,edges,N): INF = 10**10 roots=[ [] for i in range(N)] for a,b in edges: roots[a-1]+=[b-1] roots[b-1]+=[a-1] dist=[INF]*N pre = [-1]*N stack=[] stack.append(K) dist[K]=0 while stack: label=stack.pop(0) for i in roots[label]: if dist[i]==INF: dist[i]=dist[label]+1 ...
[["-", 0, 662, 12, 652, 3, 4, 0, 664, 17, 33], ["-", 0, 662, 12, 652, 3, 4, 0, 664, 28, 612], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 612]]
5
224
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; const int INF = 1001001001; vector<int> to[100005]; int main() { int n, m; cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; --a, --b; to[a].push_back(b); to[b].push_back(a); } queue<int> q; ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; const int INF = 1001001001; vector<int> to[100005]; int main() { int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; --a, --b; to[a].push_back(b); to[b].push_back(a); } queue<int> q; ...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
252
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; vector<int> g[MAXN]; int ans[MAXN]; void bfs() { queue<int> q; q.push(1); ans[1] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (0 == ans[v]) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; vector<int> g[MAXN]; int ans[MAXN]; void bfs() { queue<int> q; q.push(1); ans[1] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (0 == ans[v]) { ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
282
#include <bits/stdc++.h> #include <cmath> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define sz(x) (int)(x).size() #define v(T) vector<T> #define VEC vecto...
#include <bits/stdc++.h> #include <cmath> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define sz(x) (int)(x).size() #define v(T) vector<T> #define VEC vecto...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
509
#include <algorithm> #include <functional> #include <math.h> #include <numeric> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; int main() { int n, m; int a, b; scanf("%d %d", &n, &m); vector<vector<int>> neigh(n); for (int i = 0; i < m; ++i) { scanf("%d ...
#include <algorithm> #include <functional> #include <math.h> #include <numeric> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; int main() { int n, m; int a, b; scanf("%d %d", &n, &m); vector<vector<int>> neigh(n); for (int i = 0; i < m; ++i) { scanf("%d ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
306
from collections import deque N,M=map(int, input().split()) G=[[] for _ in range(N)] for i in range(M): a,b=map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) siru=[-1]*(N-1)#2~~N que=deque([0]) while len(que)>0: #print(que) now=que.pop() nexlist=G[now] for nex in nexlist: ...
from collections import deque N,M=map(int, input().split()) G=[[] for _ in range(N)] for i in range(M): a,b=map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) siru=[-1]*(N-1)#2~~N que=deque([0]) while que: #print(que) now=que.popleft() nexlist=G[now] for nex in nexlist: ...
[["-", 0, 656, 0, 52, 15, 666, 0, 652, 63, 22], ["-", 0, 52, 15, 666, 0, 652, 3, 4, 0, 24], ["-", 0, 52, 15, 666, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 52, 15, 666, 667, 47], ["-", 36, 36, 0, 656, 0, 52, 15, 666, 0, 612], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 319...
5
201
#include <bits/stdc++.h> using namespace std; using lint = long long int; #define rep(i, n) for (int i = 0; i < (n); ++i) const int INF = 1001001001; int main() { lint n, m; cin >> n >> m; vector<int> to[m]; //二次元配列 rep(i, m) { int a, b; cin >> a >> b; --a; --b; to[a].push_back(b); //道筋をto...
#include <bits/stdc++.h> using namespace std; using lint = long long int; #define rep(i, n) for (int i = 0; i < (n); ++i) const int INF = 1001001001; int main() { lint n, m; cin >> n >> m; vector<int> to[100005]; //二次元配列 rep(i, m) { int a, b; cin >> a >> b; --a; --b; to[a].push_back(b); //...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
266
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) #a,b = 1 2 (頂点1,2が隣接) #a,b = 2 3 (頂点2,3が隣接) #a,b = 3 4 (頂点3,4が隣接) #a,b = 4 2 (頂点2,2が隣接) #G = [[],[2],[1,3,4],[2,4],[3,2]] ans...
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) #a,b = 1 2 (頂点1,2が隣接) #a,b = 2 3 (頂点2,3が隣接) #a,b = 3 4 (頂点3,4が隣接) #a,b = 4 2 (頂点2,2が隣接) #G = [[],[2],[1,3,4],[2,4],[3,2]] ans...
[["+", 0, 7, 8, 196, 0, 57, 15, 679, 17, 354], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 0, 22], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 667, 60], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 0, 612]]
5
165
/* Author : DemonStar */ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define ordered_set \ tre...
/* Author : DemonStar */ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define ordered_set \ tre...
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73]]
1
1,042
from collections import deque n, m = map(int, input().split()) to = [[] for _ in range(n + 1)] for i in range(n): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([1]) dist = [-1] * (n + 1) # print(to) while q: v = q.popleft() for u in to[v]: if dist[u] != -1: ...
from collections import deque n, m = map(int, input().split()) to = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([1]) dist = [-1] * (n + 1) # print(to) while q: v = q.popleft() for u in to[v]: if dist[u] != -1: ...
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22]]
5
164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; const int mod = 1e6; vector<vii> adjlist; main() { int n, m; cin >> n >> m; int a, b; adjlist.assign(n + 1, vii()); while (m--) { cin >> a >> b; adjlist[a].push_back(ii(b, 1)); ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; const int mod = 1e6; vector<vii> adjlist; main() { int n, m; cin >> n >> m; int a, b; adjlist.assign(n + 1, vii()); while (m--) { cin >> a >> b; adjlist[a].push_back(ii(b, 1)); ...
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
1
264
from collections import deque n, m = map(int, input().split()) e = [[] for _ in range(n+1)] lndmrk = [-1] * (n + 1) for i in range(n): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) q = deque() lndmrk[1] = 0 q.append(1) while(len(q) != 0): v = q.popleft() for i in e[v]: if lndmrk[i] != -1: co...
from collections import deque n, m = map(int, input().split()) e = [[] for _ in range(n+1)] lndmrk = [-1] * (n + 1) for i in range(m): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) q = deque() lndmrk[1] = 0 q.append(1) while(len(q) != 0): v = q.popleft() for i in e[v]: if lndmrk[i] != -1: co...
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22]]
5
216
from collections import deque N,M = map(int,input().split()) grap = [[] for _ in range(N+1)] for i in range(M): a,b = map(int,input().split()) grap[a].append(b) grap[b].append(a) dist = [-1] * (N +1) dist[0] = 0 dist[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in grap[v]: ...
from collections import deque N,M = map(int,input().split()) grap = [[] for _ in range(N+1)] for i in range(M): a,b = map(int,input().split()) grap[a].append(b) grap[b].append(a) dist = [-1] * (N +1) dist[0] = 0 dist[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in grap[v]: ...
[["-", 0, 1, 0, 662, 12, 657, 31, 206, 51, 22], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 70], ["-", 0, 1, 0, 662, 12, 657, 31, 206, 0, 73], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
190
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++) const ll INF = 1e9; using Graph = vector<vector<int>>; int N, M; Graph G; int main() { cin >> N >> M; G.assign(N, vector<int>()); rep(i, 0, N) { int a, b; cin >> a >> b; ...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++) const ll INF = 1e9; using Graph = vector<vector<int>>; int N, M; Graph G; int main() { cin >> N >> M; G.assign(N, vector<int>()); rep(i, 0, M) { int a, b; cin >> a >> b; ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
249
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define int long long int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0...
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define int long long int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
1
328
from collections import deque n,m,*ab = map(int, open(0).read().split()) to = [set() for _ in range(n+1)] ans = [None] * (n+1) for i in range(0, n*2, 2): a = ab[i] b = ab[i+1] to[a].add(b) to[b].add(a) q = deque([1]) while q: p = q.pop() children = to[p] for child in children: if a...
from collections import deque n,m,*ab = map(int, open(0).read().split()) to = [[] for _ in range(n+1)] ans = [None] * (n+1) for i in range(0, m*2, 2): a = ab[i] b = ab[i+1] to[a].append(b) to[b].append(a) q = deque([1]) while q: p = q.pop() children = to[p] for child in children: i...
[["-", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["-", 0, 662, 12, 658, 8, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 658, 8, 652, 3, 4, 0, 25], ["+", 0, 1, 0, 662, 12, 658, 8, 634, 0, 70], ["+", 0, 1, 0, 662, 12, 658, 8, 634, 0, 73], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["-",...
5
176
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back const int mod = (int)1e9 + 7; using namespace std; int fastp(int a, int b) { int res = 1; a %= mod; while (b) { if (b & 1) res = (res * a) % mod; a *= a; a %= mod; b >>= 1; } return res % mod; } s...
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back const int mod = (int)1e9 + 7; using namespace std; int fastp(int a, int b) { int res = 1; a %= mod; while (b) { if (b & 1) res = (res * a) % mod; a *= a; a %= mod; b >>= 1; } return res % mod; } s...
[["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 43, 49, 50, 51, 2, 63, 118, 119, 120], ["+", 0, 43, 49, 50, 51, 2, 63, 118, 119, 120]]
1
346
from collections import deque import sys input = sys.stdin.readline n, m = map(int, input().split()) roots = [[] for _ in range(n)] signs = [-1 for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a, b = a - 1, b - 1 roots[a].append(b) roots[b].append(a) queue = deque([0]) signs[0] ...
from collections import deque import sys input = sys.stdin.readline n, m = map(int, input().split()) roots = [[] for _ in range(n)] signs = [-1 for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a, b = a - 1, b - 1 roots[a].append(b) roots[b].append(a) queue = deque([0]) signs[0] ...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
182