prompt
string
response
string
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...
inf = 0x101010 def solve(start,goal): cost = [inf]*n visited = [False]*n cost[start] = 0 while 1: min = inf next = -1 visited[start] = True for i in range(n): if visited[i]: continue if graph[start][i] > -1: d = cost[start] + graph[start][i] if d < cost[i]: cost[i] = d if min > cost[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> #include <algorithm> #define INF (1 << 25) using namespace std; int n,m,cost[32][32],x1,x2,y1,y2; void init(){ for(int i=0;i<32;i++){ for(int j=0;j<32;j++) cost[i][j] = INF; } } void add_info(){ int a,b,c,d; scanf("%d,%d,%d,%d",&a,&b,&c,&d); cost[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 <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) #define INF 1<<29 using namespace std; int main(){ int n,m,a,b,c,d;; cin>>n>>m; int di[n][n]; r(i,n)r(j,n)di[i][j]=(i==j)?0:INF; while(m--){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); a--;b--; di[a][b]=c; di[b][a]=d; } r(k,n)r(i,n)r(j,n)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...
inf=200000 n=int(input()) m=int(input()) adj=[[inf]*(n+1) for i in range(n+1)] for i in range(m): a,b,c,d=map(int,input().split(sep=',')) adj[a][b]=c adj[b][a]=d s,g,v,p=map(int,input().split(sep=',')) for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): adj[i][j]=min(adj[i][j],adj[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> using namespace std; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef pair<int,int> pint; typedef pair<ll,ll> pll; #define range(i,a,b) for(int i=a;i<b;++i) #define rep(i,n) range(i,0,n) const ll INF=1e10; #define pb push_back int main(){ int 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...
import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Main { static PriorityQueue <State> pq=new PriorityQueue<>(); static class State implements Comparable<State>{ int a, cost; State(int a, int cost){ this.a=a; this.cost=cost; } public int compareTo(State 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> using namespace std; int main(){ int cost[22][22]={0}; int n,m,i,j,k,a,b,c,d; char cc; cin>>n>>m; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ cost[i][j] = 1<<28; } } for(i=0;i<m;i++){ cin>>a>>cc>>b>>cc>>c>>cc>>d; cost[a][b]=c;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> #include <cstdio> using namespace std; int N, M, A, B, C, D, x1, x2, y1, y2; int K[32][32]; const int inf =1001001001; int main(){ for (int i = 0; i < 32; ++i) { for (int j = 0; j < 32; ++j) { K[i][j]= inf; } } scanf("%d%d", &N, &M); for(int i=0; i<M; ++i){ scanf("%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> using namespace std; int main(){ int n,m,a,b,c,d,COST[21][21]; for(int i=0;i<21;i++){ for(int j=0;j<21;j++){ COST[i][j] = 1000000; } } cin >> n >> m; for(int i=0;;i++){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); if(i==m) break; COST[a][b] = c; 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...
import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { int INF = 1 << 28; int n,m; int[][] map; int cost; int expense; void run() { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m= sc.nextInt(); map = new int[n][n]; for(int i=0;i<n;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<algorithm> using namespace std; #define MAX 30 #define INFTY (1<<21) int main(){ int a1, b1, c1, d1, x1, x2, y2, y1, n, m; int dai[MAX][MAX]; char v; for (int i = 0;i<MAX;i++){ for(int l=0;l<MAX;l++){ dai[i][l] = INFTY; } } cin >> n >> m; 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...
#include <cstdio> #include <algorithm> using namespace std; int main() { int n,m; scanf("%d%d", &n, &m); static int wf[50][50]; for(int i = 0; i < n; i++) fill(wf[i],wf[i]+n,1000000000); for(int i = 0; i < m; i++) { int a,b,c,d; scanf("%d,%d,%d,%d", &a, &b, &c, &d); a--; b--; wf[a][b] = c; wf[b][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<bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 100000000; const int MAX_N = 20; int dis[MAX_N + 1][MAX_N + 1]; int main() { for (int i = 0; i < MAX_N + 1; i++) { for (int j = 0; j < MAX_N + 1; j++) { dis[i][j] = INF; } } int n, m; scanf("%d",&n); scanf("%d",&m); for (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; #define rep(i,n) for(int i=0;i<n;i++) #define INF (1<<21) int main(){ int n,m,a,b,c,d; cin >> n,m; int wf[20][20]; rep(i,20)rep(j,20)wf[i][j] = (i==j?0:INF); cin >> m; rep(i,m){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); a--,b--; wf[a][b] = c , wf[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...
#include <iostream> #include <algorithm> #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define INF ( 1<<20 ) using namespace std; int costs[21][21]; int main() { int N,M; cin>>N>>M; rep1(i,N)rep1(j,N)costs[i][j] = INF; rep1(i,N)costs[i][i] = 0; char comma; 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...
import java.util.Arrays; 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 = new int[n + 1][n + 1]; for (int[] t : 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<iostream> #define N 20 #define M 10000 using namespace std; int data[N][N]; void Init(){ for(int i=0; i<N; ++i){ for(int j=0; j<N; ++j){ if(i == j) data[i][j] = 0; else data[i][j] = M; } } } void InputData(int* a, int* b, int* c, int* d){ char dm; cin >> *a >> dm >> *b >> dm >> ...
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 <string> #include <vector> using namespace std; int dist[21][21]; int main() { int n, m; char cm; cin >> n >> m; for (int i=0; i<21; ++i) { for (int j=0; j<21; ++j) { dist[i][j] = 1e6; } } int a, b, c, d; 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...
#include<iostream> #define INF 9999999 using namespace std; char ch; int MAP[21][21],mn,MN,a,b,c,d,n,m,w,x,y,z,v[21],u[21]; int compute(int start,int goal){ for(int i=1;i<=n;i++)v[i]=u[i]=INF; v[start]=0; while(1){ mn=INF; for(int i=1;i<=n;i++){ if(v[i]<mn&&u[i]==INF){ mn=v[i]; MN=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 <algorithm> #include <stdio.h> #define N 20 #define INF 10e6 int main(void){ int cost[N][N]; int n,m; int s,g,v,p; scanf("%d%d", &n, &m); for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ cost[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...
import sys sys.setrecursionlimit(10000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 def main(): N = int(input()) M = int(input()) dist = [[INF]*N for _ in range(N)] for _ in range(M): a,b,c,d = map(int,input().split(',')) a -= 1 b -= 1 dist[a][b] = c dist[b][a] = 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 <cstdio> using namespace std; #define REP(i,n) for(int i=0; i<n; i++) int main() { int n,m,a,b,ab,ba,x1,x2,y1,y2,t[32][32]; scanf("%d %d",&n,&m); REP(i,n)REP(j,n) { t[i][j]=(i==j?0:1<<20); } while(m--) { scanf("%d,%d,%d,%d",&a,&b,&ab,&ba); a--;b--; t[a][b]=ab; t[b][a]=ba; } 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<math.h> #include<vector> #include<algorithm> #include<cstdio> using namespace std; const int INF=10000000; int map[21][21]; int main(void){ int a,b,c; int d[4]; int ans; int n,m; for(a=0;a<=20;a++){ for(b=0;b<=20;b++){ map[b][a]=INF; if(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<algorithm> using namespace std; #define INF (1<<29) int m; int graph[101][101]; void wa(){ for(int i=1;i<=m;i++){ for(int j=1;j<=m;j++){ for(int k=1;k<=m;k++){ graph[j][k] = min(graph[j][k],graph[j][i]+graph[i][k]); } } } } int main(){ int n,a,b,c,d,k; 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...
class Graph(): from collections import namedtuple __Pair = namedtuple("Pair", "cost point") def __init__(self, townCount): self.__townCount = townCount self.__adjacencyList = [[] for _ in range(townCount)] def GetPath(self, beginPoint, endPoint, cost): item = self.__Pair(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...
import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); static int n, m, x1, x2, y1, y2; static int[][] edge; public static void main(String[] args) { while(read()){ solve(); } } static boolean read(){ if(!sc.hasNext())return false...
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.*; public class Main { Scanner sc = new Scanner(System.in); int Dijkstra(int[][] cost, int s, int g) { int[] tc = new int[cost.length]; Arrays.fill(tc, Integer.MAX_VALUE); tc[s] = 0; boolean[] visited = new boolean[cost.length]; 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<bits/stdc++.h> using namespace std; #define INF (1<<28) typedef pair<int,int> P; int cost1[25][25]; int main(){ int n,m; scanf("%d %d",&n,&m); for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ if(i != j) cost1[i][j] = INF; else cost1[i][j] = 0; } } int a,b,c,d; 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...
import copy def discomfort(dic, n): global Pirates, expenses, c if expenses != None and sum(p_res) >= expenses: return if n == c: if n == g_n: c = s_n discomfort(l_dic, g_n) c = g_n return else: expenses = sum(p_res) ...
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 10e6 using namespace std; int cost[20][20]; int main(void){ int n,m; char tmp; cin >> n >>m; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cost[i][j]=INF; int a,b,c,d; for(int i=0;i<m;i++){ cin >> a >> tmp >> b >> tmp >> c >> tmp >> d; cost[a-1][b-1]=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...
def f(x1, x2): W = [[i, 1001] for i in range(n)] W[x1] = [x1, 0] W[x2] = [x2, 2000] G = range(n) 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, min(...
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(void){ int n; int m; int dist[21][21]; cin >> n; cin >> m; for( int i = 0;i < 21;i++ ){ for( int j = 0;j < 21;j++ ){ dist[i][j] = 99999; } } for( int i = 0;i < 21;i++ ){ dist[i][i] = 0; } for( int i = 0;i < m;i++ ){ int a1,b1,c1,c2; scanf("%...
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<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) range(i,0,b) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 29) using namespace std; void warshallFloyd(int alt[100][100], int n){ range(k,0,n + 1){ range(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> #include <algorithm> #define INF (1e+9) #define MAX_N 20 using namespace std; int cost[MAX_N + 1][MAX_N + 1]; int N,M; void init(){ for(int i = 0;i <= MAX_N;i++){ for(int j = 0;j <= MAX_N;j++){ if(i == j) cost[i][j] = 0; else cost[i][j] = INF; } } return ; } vo...
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 = 1e+9; int main(){ int n,m,dist[21][21]; for(int i=0 ; i < 21 ; i++ ) for(int j=0 ; j < 21 ; j++ ) dist[i][j] = INF; 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); dist[...
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> const int MAX_N = 20, INF = 500000; int dis[MAX_N+1][MAX_N+1]; //V ’¸“_” from Žn“_ to I“_ int wfloyd(int V, int from, int to){ for(int k=0;k<=V;k++){ for(int i=0;i<=V;i++){ for(int j=0;j<=V;j++)dis[i][j] = std::min(dis[i][j], dis[i][k] + dis[k][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<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<vector> #include<cmath> #include<cstdio> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(),in.end...
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...
INF = 10000000 n = int(input()) m = int(input()) table = [[INF for i in range(n)] for j in range(n)] for l in range(m): a,b,c,d = [int(i) for i in input().split(",")] table[a-1][b-1] = c table[b-1][a-1] = d s,g,V,P = [int(i) for i in input().split(",")] visited = [False for i in range(n)] cost = [INF fo...
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...
V = int(input()) E = int(input()) dist = [[float('inf')] * V for _ in range(V)] for i in range(V): dist[i][i] = 0 for _ in range(E): a, b, c, d = map(int, input().split(',')) dist[a-1][b-1], dist[b-1][a-1] = c, d fr, to, money, cost = map(int, input().split(',')) for k in range(V): for i in range(V): ...
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 INF 100000000 int main(){ int n,m; cin >> n >> m; int data[n+1][n+1],a,b,c,d; char s; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) data[i][j] = INF; } for(int i=0;i<m;i++){ cin >> a >> s >> b >> s >> c >> s >> d; data[a][b] = c; data[b][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 <cstdio> #include <algorithm> using namespace std; int dp[21][21]; int main(){ int INF = (int)1e9; int n, m; int a, b, c, d; int x1, x2, y1, y2; scanf("%d%d", &n, &m); for(int i = 0; i <= n; ++i){ for(int j = 0; j <= n; ++j){ dp[i][j] = INF; } } for(int i = 0; i < m; ++i){ 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 <stdio.h> #include <algorithm> using namespace std; int n, m; int G[30][30]; int main() { for(int i=0; i<30; ++i) for(int j=0; j<30; ++j) G[i][j]=1e9; cin >> n >> m; for(int i=0; i<m; ++i){ int a, b, c, d; scanf("%d,%d,%d,%d", &a, &b, &c, &d); 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<iostream> #include<cstdio> #include<algorithm> using namespace std; const int MAX=20; const int INF=(1<<21); int main(){ int n,m; int a,b,c,d; int x1,x2,y1,y2; int road[MAX][MAX]; cin>> n>> m; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ road[i][j]=INF; } } 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...
#include <iostream> #include <algorithm> #define INF 1001 using namespace std; int main() { int m,n,a,b,c,d,x[2],y1,y2; int w[20][20],di[20],f[20]; for (int i=0; i<20; i++) { for (int j=0; j<20; j++) { w[i][j]=INF; } } scanf("%d\n%d",&n,&m); for (int i=0; i<m; i++) { scanf("%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.Scanner; public class Main { static short[][] cost; static short[] d; static final short INF = Short.MAX_VALUE/4; public static void main(String[] args) { Scanner scan = new Scanner(System.in); byte n = scan.nextByte(); cost = new short[n][n]; for (int i = 0; i < n; i++) { for (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<cstdio> #include<cstring> #include<algorithm> #include<map> using namespace std; #define INF (1<<20) int n,m; int wa[21][21]; int main(){ cin >> n; cin >> m; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) wa[i][j]=INF; for(int i=0;i<m;i++){ int a,b,c,d; scanf("%d,%d,%d,%d",&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<iostream> #include<cstdio> using namespace std; int main() { int n, m, a, b, c, d, i, j, k, x[21][21]; cin >> n >> m; for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) x[i][j] = 1001; for(i = 0; i < m; i++) { scanf("%d,%d,%d,%d", &a, &b, &c, &d); x[a][b] = c; x[b][a] = d; } for(k = 1; k <= n; 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<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、ただしd[i][i]=0とする) 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] +...
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> #define INF 200000000 int n,m; int a,b,c,d; int s,g,V,P; int mat[21][21]; int main(){ //init for(int i = 0; i < 21; i++){ for(int j = 0; j < 21; j++){ mat[i][j] = INF; if(i == j) mat[i][j] = 0; } } //input scanf("%d%d",&n,&m); for(int i = 1; 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...
#include <iostream> #include <algorithm> #include <sstream> using namespace std; const int MAXN = 21; const int INF = 1<<28; int N; int G[MAXN][MAXN]; int main() { cin >> N; for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { G[i][j] = i == j ? 0 : INF; } } int m; cin >> m; ++m; 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> using namespace std; #define INF (1<<29) int dist[30][30]; int main(){ int n, m; char dummy; cin >> n >> m; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i == j)dist[i][j] = 0; else dist[i][j] = INF; } } for(int i=0;i<m;i++){ int a, b, c, d; cin >> a >> dummy >> 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 <algorithm> #define INF 200000000 using namespace std; int main(void){ int n,m,s,t,c[2]; cin >> n >> m; int d[n][n]; fill((int *)d, (int *)d+n*n, INF); for(int i=0;i<n;i++) d[i][i] = 0; for(int i=0;i<m;i++){ cin >> s; cin.ignore(); cin >> t; cin.ignore(); cin >> c[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> #include<algorithm> using namespace std; #pragma warning(disable:4996) int x[30][30], D[30]; int N, M, a, b, c, d; int s, t, p, q; int gr(int st, int go) { for (int i = 0; i < 30; i++) { D[i] = 1145141919; } D[st] = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; 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 <cstdio> using namespace std; #define REP(i,n) for(int i=1; i<=n; i++) int main() { int n,m,a,b,c,d,x,y,z,w,t[32][32]; scanf("%d %d",&n,&m); REP(i,n)REP(j,n) { t[i][j]=(i==j?0:1<<20); } while(m--) { scanf("%d,%d,%d,%d",&a,&b,&c,&d); t[a][b]=c; t[b][a]=d; } scanf("%d,%d,%d,%d",&x,&y,&z,&w);...
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...
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(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<algorithm> #include<cstdio> #define INF (1 << 20) using namespace std; int V, E, d[20][20]; int main() { cin >> V >> E; for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++) d[i][j] = (i != j) * INF; for(int i = 0; i < E; i++) { int a, b, c1, c2; scanf("%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...
#include <iostream> #include <cstdio> using namespace std; int main() { int n; cin >> n; int M; cin >> M; int m[20][20]; fill(&m[0][0], &m[0][0]+20*20, 1e9); for (int i = 0; i < M; ++i) { int a, b, c, d; scanf("%d,%d,%d,%d", &a, &b, &c, &d); --a, --b; m[a][b] = c; m[b][a] = d; } for (int i = 0; i < n; ++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 n,m,a,b,c,d,s,g,V,P; char S; int adm[22][22]={0}; //adjacency matrix const int inf=1000000000; int main() { cin >> n >> m; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { adm[i][j]=inf; } } 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...
INF = 1e12 def dijkstra(graph, source): lg = len(graph) unused = list(range(lg)) d = [INF] * (lg) d[source] = 0 while unused: v = min(unused, key=lambda u: d[u]) unused.remove(v) for u in range(n + 1): d[u] = min(d[u], d[v] + graph[v][u]) return d n = 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 <cstdio> using namespace std; int N=0; int M, A, B, C, D, x1, x2, y1, y2; int K[32][32]; const int inf = 1001001001; int s,g,V,P; void Floyd_Warshall(){ for(int k=1;k<=N;k++){ for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ if(K[i][j]>K[i][k]+K[k][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> using namespace std; int n; int dst[100][100]; void wf(){ for(int k=0; k<n; k++){ for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(dst[i][k]+dst[k][j] < dst[i][j]){ dst[i][j] = dst[i][k]+dst[k][j]; } } } } } int main(){ int m; cin >> n >> m; 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...
''' 大工の褒美 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117&lang=jp ''' town_num = int(input()) # (<= 20) road_num = int(input()) # (<= 100) costs = [[100000]*town_num for _ in range(town_num)] # [a, b, c, d] a から b まで c, 逆は d の交通費がかかる for a, b, c, d in [list(map(int, input().split(','))) for _ in range(...
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 heapq.heappush(pq, [0,start]) while not len(pq) == 0: cur_cost,cur_node = heapq.heappop(pq) if visited[cur_no...
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 INF 1e9; using namespace std; int main(){ int n,m,a,b,c,d,s,g,v,p; int co[22][22]; cin >> n >> m; for (int i = 0;i < 22; i++)for (int j = 0;j < 22;j++)co[i][j] = INF; for (int i = 0;i < m; i++){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); co[a-1][b-1] = 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...
INF = 1000000 n = int(input()) m = int(input()) cost = [[INF] * (n + 1) for i in range(n + 1)] for i in range(m): ai, bi, ci, di = (int(s) for s in input().split(',')) cost[ai][bi] = ci cost[bi][ai] = di x1, x2, y1, y2 = (int(s) for s in input().split(',')) for k in range(1, n + 1): for i in range(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 <cstdio> using namespace std; int main(void) { int N, M; int A, B, C, D; int S, G, V, P; scanf("%d%d", &N, &M); int K[24][24]; for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) K[i][j] = 1e6; while(M) { 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.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; //A reward for a Carpentor public class Main { public static int n; public static int m; public static int[] dist; public static int[][] cost; public static int dijkstra(int s, int t){ dist = new 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...
# -*- coding: utf-8 -*- import sys import os from collections import defaultdict n = int(input()) m = int(input()) # Map M = defaultdict(list) for i in range(m): a, b, c, d = list(map(int, input().split(','))) a -= 1 b -= 1 M[a].append((b, c)) M[b].append((a, d)) s, g, V, P = list(map(int, inpu...
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> int g[20][20]; int main(){ int a,b; scanf("%d%d",&a,&b); for(int i=0;i<a;i++) for(int j=0;j<a;j++) g[i][j]=99999999; for(int i=0;i<b;i++){ int c,d,e,f; scanf("%d,%d,%d,%d",&c,&d,&e,&f); g[c-1][d-1]=e; g[d-1][c-1]=f; } int 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.awt.geom.Point2D; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new AOJ0117(); } class AOJ0117{ int cost[][]; //コスト 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> #define INF 11111111 using namespace std; int main(){ int n,m; int a,b,c,d; int x,y,r,z; int cost[100][100]; cin >> n >> m; for(int i=0;i<100;i++){ for(int j=0;j<100;j++) cost[i][j] = INF; } for(int i=0;i<m;i++){ scanf("%d,%d,%d,%d",&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> #define N 20 #define M 10000 #define rep(i,a) for(int i = 0 ; i < a ; i ++) using namespace std; int data[N][N]; void init(){ rep(i,N){ rep(j,N){ if(i==j)data[i][j] = 0; else data[i][j] = M; } } } void input(int *a,int *b,int *c,int *d){ char dm; cin >> *a >> dm >> *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<climits> using namespace std; #define NONE INT_MAX>>1 int n,m,a,b,c,d,x1,x2,y1,y2; vector< vector<int> >M; int WarshallFloyd(int start,int goal) { vector< vector<int> >A(n,vector<int>(n,NONE)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(M[i][j]!=NONE)A[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...
class Highway(object): def __init__(self, a = 0, b = 0, c = 0, d = 0): if isinstance(a,list): d = a[3] c = a[2] b = a[1] a = a[0] self.root = [int(a),int(b)] self.atob = int(c) self.btoa = int(d) def getRoot(self): return 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<cstring> #include<algorithm> #include<functional> #include<iostream> #define INF 200 #define rep(i,a) for(i=0;i<a;i++) using namespace std; int main(void) { int glid[20][20],n,m,a,b,c,d,i,j,k,p,q,w,v; cin>>n>>m; rep(i,n)rep(j,n)glid[i][j]=INF;rep(i,n)glid[i][i]=0; rep(i,m) { scanf("%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> using namespace std; const int INF=10000000; int map[21][21]; int main(void){ int a,b,c; int d[4]; int ans; int n,m; for(a=0;a<=20;a++){ for(b=0;b<=20;b++){ map[b][a]=INF; if(b==a)map[b][a]=0; } } cin >> n; cin >> m; for(a=0;a<m;a++){ scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3...
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 loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define INF 1e6 using namespace std; int main(){ int n,m,a,b,c,d,s,g,v,p; scanf("%d %d",&n,&m); int dist[n][n]; rep(i,n)rep(j,n)dist[i][j]=INF; rep(i,m){ scanf("%d,%d,%d,%d",&a,&b,&c,&d); dist[a-1][b-1]=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> using namespace std; int N, M, A, B, C, D, S, G, V, P; int K[32][32]; const int inf = 1001001001; int main() { scanf("%d%d", &N, &M); for (int i = 0; i<M; i++) { for (int j = 0; j<M; j++) { K[i][j] = inf; } } for (int i=0; i<M; i++) { scanf("%d, %d, %d, %d", &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...
import java.util.Arrays; import java.util.Scanner; public class Main { /** * @param args */ public static final int INF = Integer.MAX_VALUE; public static void main(String[] args) { doIt(); } public static void doIt(){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); //int[][] d = new 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...
def f(x1, x2): W = [[i, 1001] for i in range(n)] W[x1] = [x1, 0] W[x2] = [x2, 2000] i=0 while 1: A = sorted(W, key = lambda x:x[1]) p1, w1 = A[i] if p1 == x2: break for p2, w2 in A[i + 1:]: way=(p1, p2) if way in cost: tmp = w1 + cost[way] W[p2] = [p2, min([w2, tmp]...
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<string.h> #include<cstdio> #include<algorithm> #include<stack> #include<queue> #include<vector> #include<cmath> #include<utility> #define ll long long int #define ld long double #define INF 1000000000 #define EPS 0.0000000001 #define rep(i,n) for(i=1;i<=n;i++) using namespace std; typedef pa...
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()) K = [[10**9 for one in range(32)] for two in range(32)] for three in range(m): a,b,c,d = map(int,input().split(",")) K[a][b] = c K[b][a] = d for k in range(1,n+1): for j in range(1,n+1): for i in range(1,n+1): if K[i][j] > K[i][k] + K[k][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<string> #include<algorithm> using namespace std; const int INF = 1 << 12; int main() { int map[21][21]; int n, m,a,b,c,d; int x, y, xx, yy; char s; cin >> n; cin >> m; for (int i = 0; i <= n; i++){ for (int i2 = 0; i2 <= n; i2++){ map[i][i2] = INF; } } 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 <iostream> #include <cstdio> using namespace std; int K[20][20]; int n,m,a,b,c,d; int Floyd(int K[20][20],int n) { for(int k=0; k<n; ++k) { for(int i=0; i<n; ++i) { for(int j=0; j<n; ++j) { if(K[i][j] > K[i][k] + K[k][j]) { K[i][j] = K[i][k] + K[k][j]; } } } } return 0; } int main()...
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 n; int main(){ int m; cin >> n >> m; int graph[n+1][n+1]; //memset(graph,0,sizeof(graph)); for(int i=0;i<n+1;i++){ for(int j=0;j<n+1;j++){ graph[i][j] = 1000000; } } for(int i=0;i<m;i++){ int 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.Scanner; public class Main { static class Vertex { int number; int degree; Vertex neighbor[]; Edge edge[]; int cost; boolean mark; Vertex (int number, int n, int m) { this.number = number; this.degree = 0; neighbor = new Vertex[n]; edge = new Edge[m]; this.cost = 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...
import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { int INF = 1 << 28; int n, m; LinkedList<E>[] edges; @SuppressWarnings("unchecked") void run() { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); edges = new LinkedList[...
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) throws Exception { int INF = 1 << 28; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int fee[][] = new int[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(fe...
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.*; public class Main { int INF = 1 << 24; private void doit(){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int m = sc.nextInt(); int [][] pass = new int[n][n]; for(int i = 0 ; i < n; i++){ Arrays.fill(pass[i], INF); pass[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...
import java.util.PriorityQueue; import java.util.Comparator; import java.util.Arrays; 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(); Dijkstra dk = new Dijkstra(n); 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 <string> #include <vector> #include <algorithm> #include <climits> using namespace std; int main() { int n, m; int x1, x2, y1, y2; char dummy; cin >> n; cin >> m; vector<int> a(m), b(m), c(m), d(m); vector< vector <int> > map(n + 1, vector<int>(n + 1, INT_MAX / 4)); 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> using namespace std; const int INF=10000000; int map[21][21]; int main(void){ int a,b,c; int d[4]; int ans; int n,m; for(a=0;a<=20;a++){ for(b=0;b<=20;b++){ map[b][a]=INF; if(b==a)map[b][a]=0; } } cin >> n; cin >> m; for(a=0;a<m;a++){ scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3...
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 1000000 int C[30][30]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ C[i][j]=i==j?0:INF; } } for(int i=0;i<m;++i){ int a,b,c,d; scanf("%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.util.*; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[][] cost = new int[n+1][n+1]; for(int i=0;i<=n;i++){ Arrays.fill(cost[i], 10000); ...
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 n,m,a,b,c,d,x,y,e,f=1000000000,cnt[25][25],ans[25]; void DFS(int set,int len){ans[set]=min(len,ans[set]);for(int i=0;i<n;i++)if(len+cnt[set][i]<ans[i])DFS(i,len+cnt[set][i]);} int main(){cin>>n>>m; for(int i=0;i<n;i++){ans[i]=f;for(int j=0;j<n;j++)cnt[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> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; const int INF = 10010; int n, m, s, g, V, P; int main() { scanf("%d%d", &n, &m); vector<vector<int>> K(n, vector<int>(n, INF)); rep(i, m) { int a, b, c, d; scanf("%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...
#include <iostream> #include <cstdio> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);++(i)) int n, e, dp[22][22], s, g; const int inf = 1<<29; int solve() { for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dp[i][j] = min(dp[i][j], dp[i][k] + 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.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); sc.useDelimiter("\\D+"); final int towns = sc.nextInt(); final int paths = sc.nextInt(); int[][] relates = new int[towns][town...
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...
# Aizu Problem 0117: A reward for a Carpenter # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") # ----------------------------------------------------------------------- # Defining directed graph class: # ----------------------------...