#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000010;
vector<pair<int, int> > v[maxn];
long long dist[maxn], biao[2][maxn];
int n, q, ss, bian_cnt;
int build(int x, int l, int r, int y) {
  if (l == r) return biao[y][x] = l;
  int mid = (l + r) >> 1;
  biao[y][x] = ++bian_cnt;
  int c1 = build(x << 1, l, mid, y);
  int c2 = build((x << 1) + 1, mid + 1, r, y);
  if (y == 0) {
    v[biao[y][x]].push_back(make_pair(c1, 0));
    v[biao[y][x]].push_back(make_pair(c2, 0));
  } else {
    v[c1].push_back(make_pair(biao[y][x], 0));
    v[c2].push_back(make_pair(biao[y][x], 0));
  }
  return biao[y][x];
}
void updata(int x, int l, int r, int a, int b, int xx, int cost, int z) {
  if (l > b || r < a)
    return;
  else if (l >= a && r <= b) {
    if (z == 0) {
      v[xx].push_back(make_pair(biao[z][x], cost));
    } else {
      v[biao[z][x]].push_back(make_pair(xx, cost));
    }
    return;
  }
  int mid = (l + r) >> 1;
  updata(x << 1, l, mid, a, b, xx, cost, z);
  updata((x << 1) + 1, mid + 1, r, a, b, xx, cost, z);
}
int main() {
  cin >> n >> q >> ss;
  bian_cnt = n;
  memset(dist, -1, sizeof dist);
  build(1, 1, n, 0);
  build(1, 1, n, 1);
  for (int i = 0; i < q; i++) {
    int t, a, b, c, d;
    cin >> t >> a >> b >> c;
    if (t == 1) {
      v[a].push_back(make_pair(b, c));
    } else {
      cin >> d;
      updata(1, 1, n, b, c, a, d, t - 2);
    }
  }
  dist[ss] = 0;
  priority_queue<pair<long long, int> > Q;
  Q.push(make_pair(0, ss));
  while (!Q.empty()) {
    int now = Q.top().second;
    Q.pop();
    for (int i = 0; i < v[now].size(); i++) {
      int ve = v[now][i].first;
      int co = v[now][i].second;
      if (dist[ve] == -1 || dist[now] + co < dist[ve]) {
        dist[ve] = dist[now] + co;
        Q.push(make_pair(-dist[ve], ve));
      }
    }
  }
  for (int i = 1; i <= n; i++) cout << dist[i] << " ";
  cout << endl;
}
