prompt
string
response
string
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
#include <cstdio> int main() { int n; long long L; scanf("%d%lld",&n,&L); static long long a[100000]; for(int i=0;i<n;i++){ scanf("%lld",a+i); } int I=-1; for(int i=0;i<n-1;i++){ if(a[i]+a[i+1]>=L){ I=i; break; } } if(I==-1){ puts("Impossible"); } else{ puts("Pos...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
N,L,*A=map(int,open(0).read().split()) for i,a,b in zip(range(1,N),A,A[1:]): if a+b>=L:print("Possible",*range(1,i));print(*range(N-1,i-1,-1));quit() print("Impossible")
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { public static void main(Strin...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
N,L = map(int,input().split()) src = list(map(int,input().split())) for i,(a,b) in enumerate(zip(src, src[1:])): if a+b >= L: print('Possible') for j in range(1,i+1): print(j) for j in range(N-1,i,-1): print(j) exit() print('Impossible')
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
N, L = map(int, input().split()) A = list(map(int, input().split())) d = [A[i] + A[i+1] for i in range(N-1)] if max(d) < L: print("Impossible") else: print("Possible") j = 0 while d[j] < L: j += 1 for i in range(j): print(i+1) for i in range(j, N-1): print(N-i+j-1)
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
import sys input = sys.stdin.readline N, L = map(int, input().split()) a = list(map(int, input().split())) s = -1 for i in range(N - 1): if a[i] + a[i + 1] >= L: s = i break if s == -1: print("Impossible") exit(0) res = [s] for i in range(s - 1, -1, -1): res.append(i) for i in range(s + 1, N - 1): res...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int l = sc.nextInt(); int [] a = new int [n]; long total = 0; boolean ok = false; int stor = -1; for (int i = 0; i < n; i++) { ...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
def get_ints(): return list(map(int, input().split())) [n, l] = get_ints() a = get_ints() for i in range(n - 1): if a[i] + a[i + 1] < l: continue print("Possible") for j in range(1, i + 1): print(j) for j in range(n - 1, i, -1): print(j) exit(0) print("Impossible")
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
import java.io.*; import java.util.*; class Main { public static InputReader in; public static PrintWriter out; public static final int MOD = (int) (1e9 + 7); public static void main(String[] args) { in = new InputReader(System.in); out = new PrintWriter(System.out); ...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
n,l=[int(x) for x in input().split()] a=[int(x) for x in input().split()] j=-1 for i in range(n-1): if a[i]+a[i+1]>=l: j=i break if j==-1: print("Impossible") else: #print(j) print("Possible") for i in range(j): print(i+1) for i in range(n-1,j,-1): print(i)
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
n,l = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) for i in range(n-1): if a[i]+a[i+1] >= l: print('Possible') for j in range(n,i+2,-1): print(j-1) for k in range(1,i+2): print(k) exit() print('Impossible')
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
#include <stdio.h> long long a[101010]; int main(){ int n; long long l; scanf("%d%lld",&n,&l); for(int i=0;i<n;i++)scanf("%lld",&a[i]); for(int i=0;i+1<n;i++){ if(a[i]+a[i+1]>=l){ puts("Possible"); for(int j=1;j<=i;j++)printf("%d\n",j); for(int j=n-1;j>=i+1;j--)printf("%d\n",j); return 0; } } ...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
#include <stdio.h> int N,L; int a[100000]; int i,j,ans; int main(void){ scanf("%d %d",&N,&L); for(i=0;i<N;i++){ scanf("%d",&a[i]); } ans = N; for(i=0;i<N-1;i++){ if(a[i]+a[i+1]>=L){ ans = i; } } if(ans == N){ printf("Impossible\n"); }else{ printf("Possible\n"); for(i=0;i<ans;i++){ prin...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
N, L = map(int, raw_input().split()) a = map(int, raw_input().split()) b = [a[i]+a[i+1] for i in xrange(N-1)] maxb = max(b) maxbi = b.index(maxb) if maxb < L: print 'Impossible' exit() print 'Possible' for i in xrange(maxbi): print i+1 for i in xrange(N-2, maxbi, -1): print i+1 print maxbi+1
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
#include <bits/stdc++.h> using namespace std; int N; int L; int as[114514]; int main() { scanf("%d%d", &N, &L); for (int i=0; i<N; i++) { scanf("%d", &as[i]); } for (int i=1; i<N; i++) { if (as[i-1] + as[i] >= L) { puts("Possible"); for (int j=1; j<i; j++) { printf("%d\n", j); ...
Problem: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) ro...
#include <cstdio> const int MAXN = 1e5; typedef long long LL; int A[MAXN]; int main() { int N, L, idx = -1, i; scanf("%d%d", &N, &L); for(i=0; i<N; ++i) scanf("%d", A+i); for(i=1; i<N; ++i) if(LL(A[i-1])+A[i] >= L) { idx = i; break; } if(idx == -1) puts("Impossible"); else { puts("Possible"); ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> using namespace std; static const int INF = 9999999; void solve() { int n, m; cin >> n >> m; int d[21][21]; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { d[i][j] = INF; } } char c; for(int i = 0; i < m; ++i) { int a1, b1, c1, d1; cin >> a1 >> c >> b1 >> c >> c1 >>...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define INF (1<<29) int main() { int n, m, s, g, V, P; int mincost[20][20]; cin >> n >> m; REP(i, n) REP(j, n) { if (i == j) mincost[i][j] = 0; else mincost[i][j] = INF; } REP(i, m) {...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; int main() { int n; int m; int a, b, c, d, s, g, V, P; int cost, reward; scanf("%d%d", &n, &m); int K[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) K[i][j] = 100010010; } for (int i = 0; i < m; i++) { scanf("%d,%d,%d,%d", ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.io.BufferedReader; import java.io.InputStreamReader; class Main { /* * 問題URL : https://onlinejudge.u-aizu.ac.jp/#/problems/0117 */ private static final int INFINITY = Integer.MAX_VALUE/2; public static void main(String[] args) throws Exception { //入力 BufferedReader br = new BufferedReader(ne...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> using namespace std; int dp[20][20]; void solv(int n){ for(int k = 0;k < n;k++){ for(int i = 0;i < n;i++){ for(int j = 0;j < n;j++){ if(dp[i][j] > dp[i][k] + dp[k][j]){ dp[i][j] = dp[i][k] + dp[k][j]; } } } } } int main(){ int n, m, a, b, c, d; char s; fill((int*)dp, (i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
def floyd(P,m): for k in range(m): for i in range(m): for j in range(m): P[i][j]=min(P[i][j],P[i][k]+P[k][j]) n=input() m=input() INF=1e10 C=[[INF]*n for i in range(n)] for i in range(n): C[i][i]=0 for i in range(m): a1,b1,c1,d1=map(int,raw_input().split(",")) C[a1-1...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class Main { static int n,m,s,g,money,pillar; static int[][] edge; static int[][] min; public static void main(String[] args) { Scanner cin = new Scanner(System.in); n=cin.nextInt(); m=cin....
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<cstdio> using namespace std; #define INF 1001001001 int n,m,a,b,c,d,x1,x2,y1,y2; int r[21][21]; int used[21],dis[21]; int select(){ int p=INF,q; for(int i=1;i<=n;i++){ if(used[i]==0&&dis[i]<p){ p=dis[i];q=i; } } return q; } int dijkstra(int s,int g){ int q=1,u; for(int i=0;i<=n...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import sys n = int(input()) m = int(input()) cost = [[float("inf")] * n for _ in range(n)] for _ in range(m): a, b, c, d = map(int, sys.stdin.readline().split(",")) cost[a - 1][b - 1] = c cost[b - 1][a - 1] = d s, g, V, P = map(int, sys.stdin.readline().split(",")) for k in range(n): for i in range(n):...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.*; import java.io.*; public class Main{ final int INF = 1000000001; public int search(int[][] graph, int start, int goal){ int[] cost = new int[graph.length]; for(int i = 0; i < cost.length; i++){ if( i == start ){ cost[i] = 0; continue; } cost[i] = INF; } Set<Integer> ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; const int INF = 10000000,MAX = 21; int main(){ int n,m,edge[MAX][MAX],a,b,c,d,s,g,p,pp; cin >> n >> m; for(int i = 0;i < MAX;++i){ for(int j = 0;j < MAX;++j){ edge[i][j] = INF; } edge[i][i] = 0; } for(int i = 0;i < m;++i){ s...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<stdio.h> #define INF 9999999 using namespace std; char ch; int n,m,t[21][21],u[21],v[21],a,b,c,d; int cost(int start,int goal){ int mini,miniNo; for(int i=0;i<21;i++){ u[i]=INF; v[i]=0; } u[start]=0; while(1){ mini=INF; for(int i=1;i<=n;i++){ if(v[i]==0&&u[i]<mini){ miniN...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<algorithm> using namespace std; int main() { int n, m, a, b, c, d, s[22][22], inf = 100000, i, j, k; char temp; cin >> n; cin >> m; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i != j) { s[i][j] = inf; } else { s[i][j] = 0; } } } for (i = 0; i < m; i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#import<cstdio> int main(){int i,j,k,a,b,c,d,n,m,D[21][21];for(i=0;i<21;i++)for(j=0;j<21;j++)D[i][j]=1e+9;scanf("%d%d",&n,&m);for(i=0;i<m;i++)scanf("%d,%d,%d,%d", &a, &b, &c, &d),D[a][b]=c,D[b][a]=d;for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)D[i][j]=(D[i][j]<D[i][k]+D[k][j])?D[i][j]:D[i][k]+D[k][j];scanf("%d,%d...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<cstdio> #include<algorithm> #define INF (1<<29) using namespace std; int g[21][21]; int V; int main(void){ fill(g[0],g[21],INF); int n; cin >> V >> n; int a,b,c,d; for(int i=0;i<n;i++){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); g[a][b]=c,g[b][a]=d; } int x1,x2,y1,y2; s...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <algorithm> using namespace std; #define INF 1e9 int v, m; int D[21][21]; void warshall_floyd(){ for(int k = 1; k <= v; k++){ for(int i = 1; i <= v; i++){ for(int j = 1; j <= v; j++){ D[i][j] = min(D[i][j], D[i][k] + D[k][j]); } } } } int main(void){ int x1, x2, y1, y2; i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<bits/stdc++.h> using namespace std; #define MAX_V 25 #define INF 1<<21 int d[MAX_V][MAX_V]; //d[u][v]テ」ツ?ッティツセツコe=(u,v)テ」ツ?ョテ」ツつウテ」ツつケテ」ツδ?テ・ツュツ佚・ツ慊ィテ」ツ?療」ツ?ェテ」ツ??・ツ?エテ・ツ青暗」ツ?ッINFテ」ツ??」ツ?淌」ツ??」ツ?妖[i][i]=0テ」ツ?ィテ」ツ?凖」ツつ? int n, m; //テゥツ?づァツつケテヲツ閉ー void warshall_floyd(){ for(int k = 0; k < n; k++){ for(int i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <vector> //#include <algorthm> #include <stdio.h> #include <stdlib.h> using namespace std; const int MAX = 1<<28; int main(){ int n,m; cin >> n >> m; vector<vector<int> > map1(n,vector<int>(n,MAX)); //vector<vector<int> > map2(n,vector<int>(n,MAX)); for(int i = 0;i < m;i++){ ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
//A_reward_for_a_Carpenter.cc #include <iostream> #include <cstdio> #define Inf 1001001001 using namespace std; int main() { int n,m,s,g,V,P,i,j,k,last; int K[32][32]; scanf("%d",&n); scanf("%d",&m); //cin >> n >> m; int a[110],b[110],c[110],d[110]; for(i=1;i<32;i++) for(j=1;j<=32;...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> #include <string> #include <stack> #include <cstdlib> #include <queue> #include <vector> #include <set> #include <stdio.h> #include <cstdio> using namespace std; int n,m,a,b,ab,ba,x1,x2,y1,y2; int co[20][20]; int main() { scanf("%d%d", &n, &m); for (int i=0; i <n;i++) { for...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<cstdio> #include<algorithm> using namespace std; #define INF 9999999 int main(){ int n,m; scanf("%d%d",&n,&m); int D[36][36];/*Adjacency matrix*/ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(i == j)continue; D[i][j] = INF; } } for(int i = 0; i < m; i++){ int a,b,c,d; s...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define shosu(n) setprecision(n) #define INF 1000000000; using namespace std; int main() { int n, m; char q; cin >> n >> m; int dp[n][n]; rep(i, n) rep(j, n) dp[i][j] = i == j ? 0 : INF; rep(i, m) { int a, b, c, d; cin >> a >> ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#dijkstra from heapq import heappop as pop from heapq import heappush as push INF = 10 ** 20 n = int(input()) m = int(input()) edges = [[] for _ in range(n)] for _ in range(m): a, b, c, d = map(int, input().split(",")) a, b = a - 1, b - 1 edges[a].append((b, c)) edges[b].append((a, d)) s, g, v, p = map(in...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
n = int(input()) m = int(input()) inf = 1001001001 route = [[inf for _ in range(n)] for __ in range(n)] for _ in range(m): a, b, c, d = map(int, input().split(',')) route[a-1][b-1] = c route[b-1][a-1] = d s, g, V, P = map(int, input().split(',')) for k in range(n): for i in range(n): for j in ra...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<cstdio> #include<iostream> #include<algorithm> #include<functional> #define rep(i,a) for(i=0;i<a;i++) #define LL long long int #define MAX_VAL 2100000000 using namespace std; LL dist[114][114]; int main(void) { int n,m,i,j,k; int a,b,c,d; int s,g,v,p; cin>>n>>m; rep(i,n)rep(j,n)dist[i][j]=MAX_VAL; rep(i,...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<stdio.h> using namespace std; const int NUM = 25; int main() { int wf[NUM][NUM]; for ( int i = 0; i < NUM; i++ ) { for ( int j = 0; j < NUM; j++ ) { if ( i == j ) { wf[i][j] = 0; } else { wf[i][j] = 100000; } } } int n,m; cin >> n >> m; for ( int i = 0; i < m...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define INF 1000000000 int n,m,r[21][21],cost[21][21]; int x1,x2,y1,y2; int d[21]; int BF(int a,int b){ for(int i=0;i<21;i++)d[i]=INF; d[a]=0; for(int i=0;i<n*2;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ if(r[j...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define INF 1000000 int n, m; int cost[32][32]; int x1, x2, y1, y2; void init() { for(int i = 0; i < 32; i++) for(int j = 0; j < 32; j++) cost[i][j] = INF; for(int i = 0; i < 32; i++) cost[i][i] = 0; } void input() { int a, b,...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) int D[30][30]; int main() { int n, m; scanf("%d%d", &n, &m); memset(D, 0x0f, sizeof(D)); REP(i, n) { D[i][i] = 0; } REP(i, m) { int a, b, c, d; scanf("%d,%d,%d,%d", &a, &b, &c, &...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <cstdlib> #include <vector> using namespace std; template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; } int main() { const int INF = (1 << 29); int n, m; scanf("%d\n%d", &n, &m); vector<vector<int>> mat(n, vector<int>(n, INF)); for(int i = 0; i < n; ++i) { mat[i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
/* A reward a Carpenter */ import java.io.*; import java.util.*; public class Main{ public static void main(String args[]){ try{ new Main(); }catch(IOException err){ err.printStackTrace(); } } public Main() throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(), b = s.nextInt(); int[][] g = new int[a][a]; for (int i = 0; i < a; i++) { Arrays.fill(g[i], 99999999);...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; // int main(void){ char str; int n, m, a, b, c, d, s, g, s_cost, g_cost; int cost[21][21]; cin >> n >> m; for (int i = 1; i < n+1; i++){ for (int j = 1; j < n+1; j++) cost[i][j] = 1001; } for (int i = 0; i < m; i++){ cin >> ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
# AOJ 0117 A reward for a Carpenter # Python3 2018.6.21 bal4u INF = 0x7fffffff import heapq def dijkstra(V, to, start, goal): dist = [INF]*V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while len(Q): t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for i in to[s]: e, cost =...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> using namespace std; int r[400][4]; int d[21][21]; int main(){ int n,m,x1,x2,y1,y2,i,j,k; cin>>n>>m; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ d[i][j]=1000000; } } for(i=0;i<m;i++){ scanf("%d,%d,%d,%d",&r[i][0],&r[i][1],&r[i][2],&r[i][3]); d[r[i][0]][r[i][1]]=r[i][2]; d[r[i][1]][r[i][...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> using namespace std; int main() { char c; int x1,x2,y1,y2; int n,m,a,b,ab,ba; int tb[32][32]; cin >> n >> m; for(int i=0; i<n; i++) for(int j=0; j<n; j++) { tb[i][j] = (i==j ? 0 : 1<<20); } while(m--) { cin >> a >> c >> b >> c >> ab >> c >> ba; a--; b--; tb[a][b] = ab; tb[b][...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<vector> #include<queue> #include<stack> #include<map> #include<string> #include<algorithm> #include<utility> #include<math.h> using namespace std; typedef long long int ll; typedef pair<int, int> P; const int INF = pow(10, 8); int main(){ int n, m;cin>>n>>m;char z; vector<vector<int> > d...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<algorithm> #include<cstdio> #include<vector> #include<cstring> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);++i) const int inf = 100100100; int edge[30][30]; int main() { int N, M; scanf("%d%d", &N, &M); REP(i, N) REP(j, N) edge[i][j] = inf; REP(i, N) edge[i][i] = 0;...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; #define INF 1 << 16 int main() { int cost[20][20]; fill(&cost[0][0], &cost[0][0]+20*20, INF); int n; cin >> n; int m; cin >> m; for (int i = 0; i < m; ++i) { int a, b, c, d; scanf("%d,%d,%d,%d\n", &a, &b, &c, &d); --a, --b; cost[a][b] = c; cost[b...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define INF (1 << 29) int main(){ int n, m; int cost[21][21]; int a, b, c, d; for(int i = 0 ; i < 21 ; i++){ for(int j = 0 ; j < 21 ; j++){ cost[i][j] = INF; if(i == j) cost[i][j] = 0; } ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<bits/stdc++.h> using namespace std; #define MAX_V 25 #define INF 1<<21 int d[MAX_V][MAX_V]; int n, m; void warshall_floyd(){ for(int k = 0; k < n; k++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } int main(){ for(int i = 0; i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<bits/stdc++.h> using namespace std; int mini[21][21]; const int Inf = 1e5; int main(){ int n,m; cin >> n >> m; for(int i=0;i<=n;++i){ for(int j=0;j<=n;++j){ if(i == j)mini[i][j] = 0; else mini[i][j] = Inf; } } for(int i=0;i<m;++i){ int a,...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; int N,M,A,B,C,D,x1,x2,y1,y2; int P[32][32]; const int inf = 1001001001; int main() { for(int e=0;e<32;++e){ for(int f=0;f<32;++f){ P[e][f]=inf; } } scanf("%d%d", &N, &M); for(int g=0;g<M;++g){ scanf("%d,%d,%d,%d", &A, &B, &C, &D); P[A][B]=C; P[...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> #define INF 10000000 using namespace std; int cost[21][21]; int m,n; void W(){ for(int k = 0 ; k < n ; k++ ){ for(int i = 0 ; i < n ; i++ ){ for(int j = 0 ; j < n ; j++ ){ cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]); } } } } int main(){ c...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.ArrayDeque; import java.util.Arrays; import java.util.Deque; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); int[][] num...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include "bits/stdc++.h" using namespace std; #define rep(i, n) for(int i=0;i<(n);i++) int N, M, A, B, C, D,s,g,V,P; int K[32][32]; const int inf = 1001001001; int main() { rep(i, 32) { rep(j, 32) K[i][j] = inf; } cin >> N; cin.ignore(); cin >> M; rep (i,M) { cin >> A; cin.ignore(); cin >> B; cin.ign...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> using namespace std; #define rep(i,s,n) for(int i=s;i<n;i++) #define REP(i,n) rep(i,0,n) #define NMAX 21 #define INF 1<<26 int dist[NMAX][NMAX]; int n,m; int x1,x2,y1,y2; void init(){ REP(i,NMAX)REP(j,NMAX)dist[i][j]=INF; } void wf(){ rep(k,1,n+1){ rep(i,1,n+1){ rep(j,1,n+1){ dist[i][j]=...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<queue> #include<vector> #include<algorithm> #include<stack> #include<map> #include<set> #include<cstdio> #include<cmath> #include<string> #define REP(i,n) for(int i=0;i<(int)(n);i++) typedef long long ll; #define INF 1e9 using namespace std; int main() { int n,m; scanf("%d %d",&n,&m);...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
N = int(input().strip()) M = int(input().strip()) Inf = 1001001001 K = [[Inf for j in range(N)] for i in range(N)] for _ in range(M): a,b,c,d = map(int,input().strip().split(",")) K[a-1][b-1] = c K[b-1][a-1] = d S,G,V,P = map(int,input().strip().split(",")) for k in range(N): for i in range(N): ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
//A Reward for a Carpenter #include <iostream> #include <cstdio> #define rep(i,n) for(int i = 0;i < n;i++) #define mp make_pair using namespace std; const int inf = 1e9; int dis[30][30]; int main(){ int n,m; cin >> n>>m; rep(i,n){ rep(j,n){ dis[i][j]=inf; } } rep(i,n){ ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import heapq def dijkstra(start,goal,graph): INF = 2 << 20 node_num = len(graph) visited = [False] * node_num costs = [INF] * node_num pq = [] costs[start] = 0 #print costs[start] heapq.heappush(pq, [0,start]) while not len(pq) == 0: cur_cost,cur_node = heapq.heappop(p...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117 #include <iostream> #include <vector> using namespace std; const int INF = 1<<28; int main(){ int n,m; cin>>n>>m; char dummy; vector<vector<int>> d(n, vector<int> (n,INF)); for(int i=0;i<m;++i){ int a,b,c,e; cin>>a>>dummy>>b>>dummy>>c>...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int n=s.nextInt()+1,m=s.nextInt(),i=1,j,t;int[] p=new int[n*n];Arrays.fill(p,9999999);for(;i<n;++i)p[i*n+i]=0;for(;m-->0;){z=s.next().split(",");i=new Integer(z[0]);j=new Integer(z[1]);p[i*n+j]=new Integer(z[2]);p[j*n+i]=n...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<cstdio> #include<cassert> using namespace std; int main(){ int n,m,a,b,c,d,s,g,money,pay,matrix[40][40]; for(int i=0;i<40;i++)for(int j=0;j<40;j++)matrix[i][j]=1<<22; cin >> n; cin >> m; for(int i=0;i<m;i++){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); matrix[a][b] = c; matrix[...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int wf[20][20]; int n,m,a,b,c,d; cin >> n >> m; rep(i,n)rep(j,n)wf[i][j]=(1<<21); rep(i,m){ scanf("%d,%d,%d,%d\n",&a,&b,&c,&d); a--;b--; wf[a][b] = c; wf[b][a] = d; } scanf("%d,%d,%d,%d\n",&a,...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
n = int(input()) m = int(input()) Map = [[1001]*n for _ in range(n)] for _ in range(m): a,b,c,d = map(int,input().split(",")) Map[a-1][b-1] = c Map[b-1][a-1] = d s,g,V,P = map(int,input().split(",")) for k in range(n): for i in range(n): for j in range(n): if Map[i][j] > Map[i][k]+...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * A Reward for a Carpenter */ public class Main { static Main main = new Main(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <cstring> #define rep(i,n)for(int i=0;i<n;i++) #define min(a,b)((a)<=(b)?(a):(b)) int n,m; int a,b,c,d; int x1,x2,y1,y2; int cost[20][20]; int main() { memset(cost,0x10,sizeof(cost)); scanf("%d",&n); scanf("%d",&m); rep(i,m) { scanf("%d,%d,%d,%d",&a,&b,&c,&d); a--;b--; cost[a][b]=c;...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n, m; int D[20][20]; int V; const int INF = 1 << 20; void solve() { for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { D[i][j] = min(D[i][j], D[i][k] + D[k][j]); } } } } i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<stdio.h> #include<math.h> #include<iostream> #include<algorithm> #define SIZE 100 #define INF 1000000 using namespace std; int main(){ int i,j,k; int n,m; int a,b,c,d; int s,g,x,y; int cost[SIZE][SIZE]; cin>>n; cin>>m; for(i=1;i<n+1;i++){ for(j=1;j<n+1;j++){ cost[i][j]=INF; }...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
//22 #include<iostream> #include<algorithm> using namespace std; int main(){ int n,m; cin>>n>>m; int d[21][21]; fill_n(d[0],21*21,1<<29); for(int i=0;i<m;i++){ int a[4]; for(int i=0;i<4;i++){ cin>>a[i]; cin.ignore(); } d[a[0]][a[1]]=a[2]; d[a[1]][a[0]]=a[3]; } for(int i=1...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> using namespace std; const int MAX_V = 1000; const int LIMIT = 999999; int d[MAX_V][MAX_V]; // コスト i==jのとき0, それ以外INF int n, m; // 町, 街道 void warshall_floyd() { for(int k=0; k<m; k++) for(int i=0; i<m; i++) for(int j=0; j<m; j++) d[i][j]=min(d[i][j], d[i][k]+d[k]...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> #define MAX_N 21 #define INF 1e+9 using namespace std; int main(void){ int n,m;cin>>n>>m; int g[MAX_N][MAX_N]; for(int i=0;i<MAX_N;++i)for(int j=0;j<MAX_N;++j)g[i][j]=INF; for(int i=0,a,b,c,d;i<m;++i){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); g[a][b]=c; g[b][a]=d; } int d[MAX_...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; 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(); Graph g = new Graph(n); for(int i=0;i<m;i++) { Stri...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * A Reward for a Carpenter */ public class Main { static Main main = new Main(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> using namespace std; #define N 21 #define INF 1000000007 #define min(a,b) (a>b?b:a) int mat[N][N]; int main() { int n, m, a, b, c, d, x1, x2, y1, y2; char du; cin >> n >> m; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) mat[i][j] = INF; for(int i=0; i<m; ++i) { cin >> a >> du >> b >> du >>...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int M = 100000; void run() { int n = sc.nextInt(); int m = sc.nextInt(); int[][] graph = new int[n + 1][n + 1]; for (int i = 0; i <= n; i++) { Arrays.fill(graph[i], M); } for (int i = 0; i < m...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<iostream> #include<vector> #include<climits> using namespace std; #define NONE INT_MAX>>1 vector< vector<int> > WarshallFloyd(vector< vector<int> >A) { for(int k=0;k<A.size();k++)for(int i=0;i<A.size();i++)for(int j=0;j<A.size();j++) A[i][j]=min(A[i][j],A[i][k]+A[k][j]); return A; } int main() { i...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; int N, M, A, B, C, D, x1, x2, y1, y2, Ans; int main(){ scanf("%d%d", &N, &M); int K[N+10][N+10]; for(int i=1; i<=N; i++){ for(int j=1; j<=N; j++){ K[i][j] = 2000; } } for(int i=1; i<=M; i++){ scanf("%d,%d,%d,%d", &A, &B, &C, &D); ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <algorithm> using namespace std; const int INF=100000000; int dp[20][20]; int main(){ for(int i=0;i<20;i++){ for(int j=0;j<20;j++){ if(i!=j) dp[i][j]=INF; } } int n,m,s,g,V,P; scanf("%d",&n); scanf("%d",&m); int a,b,c,d; while(m--){ scanf("%d,%d,%d,%d",&a,&b,&c...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<bits/stdc++.h> #define rep(i,n) for(int i=1;i<=n;i++) #define MAX 200000000 using namespace std; int main(void) { int n,m; int a,b,c,di; int s,g,v,p; int d[21][21]; char ch; cin>>n>>m; rep(i,n)rep(j,n)d[i][j]=(i==j)?0:MAX; rep(i,m){ cin>>a>>ch>>b>>ch>>c>>ch>>di; d[a][b]=c; d[b][a]=di; } rep(k,n...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> #define inf 999999 using namespace std; int main(int argc, char **argv) { int f[21][21], n, m, a, b, c, d; while(cin >> n >> m){ fill(&f[1][1], &f[n+1][n+1], inf); for(int i = 1; i <= n; i++){ f[i][i] = 0; } while(m--){ scanf("%d,%d,%d,%d", &a, &b, &c, &d)...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
def f(x1, x2): W=[[i,1000] for i in range(n)] W[x1]=[x1,0] W[x2]=[x2,2000] G = range(n); G=G[x2:]+G[:x2] while 1: A = sorted([W[e] for e in G], key=lambda x: x[1]) p1, w1 = A[0] G.remove(p1) if p1==x2: break for p2, w2 in A[1:]: way=(p1, p2) if way in cost: W[p2] = [p2,...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
n=int(input()) cost=[[float('inf')]*n for _ in range(n)] m=int(input()) for _ in range(m): a,b,c,d=map(int,input().split(',')) cost[a-1][b-1]=c cost[b-1][a-1]=d s,g,V,P=map(int,input().split(',')) for k in range(n): for i in range(n): for j in range(n): if cost[i][j] > cost[i][k] + ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <algorithm> #define INF 1000000 using namespace std; int main(){ int n,m,a,b,c,d; char ch; int cost[21][21]; for(int i=0;i<21;i++){ for(int j=0;j<21;j++){ cost[i][j]=INF; } } cin>>n>>m; for(int i=0;i<m;i++){ cin>>a>>ch>>b>>...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main{ Scanner sc=new Scanner(System.in); int INF=1<<28; double EPS=1e-9; int n, m; void run(){ sc.useDelimiter("[,]|(\\s)+"); n=sc.nextInt(); m=sc...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <cstdio> #include <algorithm> using namespace std; int cost[20][20]; int main() { for(int i=0;i<20;i++) { for(int j=0;j<20;j++) { if(i!=j)cost[i][j]=cost[j][i]=1<<27; else cost[i][i]=0; } } int n,m; scanf("%d %d",&n,&m); for(int i=0;i<m;i++) { int a,b,c,d; scanf("%d,%d,%d,%d",&a,&b,&c,&d); ...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { static void setEdge(List<ArrayList<int[]>> edge, String input) { String[] str = input.split(","); int from = Integer.parseInt(str[0]); int to = Integer.parseInt(str[1]); int cost1 = Integer.parseInt(str[2]); int...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <vector> #include <queue> #include <string> #include <memory> #include <memory.h> using namespace std; int d[21][21]; int main(){ char ch; int n, m; memset(d, -1, sizeof(d)); int x1, x2, y1, y2; cin >> n >> m; for(int i = 0; i < m; i++){ int a, b, c, d2; cin >> a >> c...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include <iostream> #include <cstdio> using namespace std; int N,M,A,B,C,D,x1,x2,y1,y2; int K[32][32]; const int inf =1001001111; int main() { for(int j=0;j<32;j++){ for(int jj=0;jj<32;jj++){ K[j][jj]=inf; } } scanf("%d%d",&N,&M); for(int ii=0;ii<M;ii++){ scanf("%d,%d,%d,%d",&A,&B,&C,&D); K[A][B]=C; K[B][A]=D...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<algorithm> const int INF = 1001; const int V = 20; int dis[V][V]; int n, m; void warshall_floyd(){ for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j)dis[i][j] = std::min(dis[i][j], dis[i][k] + dis[k][j]); } int main(){ s...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main{ public static void main(String[] args)throws IOException{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(isr); int n =...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
#include<algorithm> #include<iostream> #include<string> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; int main(){ int i,j,k; int a[20][20],m,n,o,p,q,r; cin>>n>>m; for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=200000000; for(i=0;i<m;i++){ int t,u,v,w; s...
Problem: One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go t...
import static java.lang.System.*; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Map.Entry; import java.util.Random; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; class Main { public static ...