#include<bits/stdc++.h>
using namespace std;

int main()
{

    long long int n,m,i,j,a[200005],s=0,x,y,mn,mx;

    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>a[i];
     s=s+a[i];
    }
if(n==1){
    cout<<a[1]-1<<endl;
    return 0;
}
if(s==m){
    for(i=1;i<=n;i++)
        cout<<a[i]-1<<" ";
}
else{
for(i=1;i<=n;i++){
    mn=n-1;
    mx=s-a[i];
    if(mn+a[i]<=m){
        if(mx<m){
            y=m-mx-1;
            cout<<y<<" ";
        }
        else{
            cout<<0<<" ";
        }
    }
    else{
        x=m-mn;
        y=a[i]-x;
        cout<<y<<" ";
    }
}
}

}


// --- http://www.voidcn.com/article/p-hioedrnk-da.html

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll a[200500];
int main()
{
    ll n,k,maxn,minn;
    while(~scanf("%I64d%I64d",&n,&k))
    {
        memset(a,0,sizeof(a));
        maxn=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&a[i]);
            maxn+=a[i];
        }
        minn=n-1;
        for(int i=1;i<=n;i++)
        {
            maxn-=a[i];
            ll r=k-minn;
            ll l=k-maxn;
            ll l2=1;
            ll r2=a[i];
            ll zuo=max(l,l2);
            ll you=min(r,r2);
            ll tmpp=a[i]-(you-zuo+1);
            printf("%I64d ",tmpp);
            maxn+=a[i];
        }
        printf("\n");
    }
}


// --- http://www.voidcn.com/article/p-hioedrnk-da.html
// --- http://www.voidcn.com/article/p-kczlxdrc-bx.html

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll a[200500];
int main()
{
    ll n,k,maxn,minn;
    while(~scanf("%I64d%I64d",&n,&k))
    {
        memset(a,0,sizeof(a));
        maxn=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&a[i]);
            maxn+=a[i];
        }
        minn=n-1;
        for(int i=1;i<=n;i++)
        {
            maxn-=a[i];
            ll r=k-minn;
            ll l=k-maxn;
            ll l2=1;
            ll r2=a[i];
            ll zuo=max(l,l2);
            ll you=min(r,r2);
            ll tmpp=a[i]-(you-zuo+1);
            printf("%I64d ",tmpp);
            maxn+=a[i];
        }
        printf("\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll min(ll a,ll b)
{
    if(a>b)
    return b;
    else
    return a;
}
ll max(ll a,ll b)
{
    return a+b-min(a,b);
}
int main()
{
    ll n,s,arr[200001],sum[200001];
    sum[0]=0;
    cin>>n>>s;
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum[i]=arr[i]+sum[i-1];
    }
    if(n==1)
    {
        cout<<arr[1]-1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        if(s-(sum[n]-arr[i])<=0)
        cout<<max(0,max(arr[i]-s,arr[i]-(s-(n-1))))<<" ";
        else
        {
            if(sum[n]-arr[i] >arr[i])
            cout<<max(0,s-(sum[n]-arr[i])-1)<<" ";
            else
            cout<<max(0,arr[i]-(n-1)-1)<<" ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll min(ll a,ll b)
{
    if(a>b)
    return b;
    else
    return a;
}
ll max(ll a,ll b)
{
    return a+b-min(a,b);
}
int main()
{
    ll n,s,arr[200001],sum[200001];
    sum[0]=0;
    cin>>n>>s;
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum[i]=arr[i]+sum[i-1];
    }
    if(n==1)
    {
        cout<<arr[1]-1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        if(s-(sum[n]-arr[i])<=0)
        cout<<max(0,max(arr[i]-s,arr[i]-(s-(n-1))))<<" ";
        else
        cout<<max((s-(sum[n]-arr[i]))-1,arr[i]-(n-1)-1)<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll min(ll a,ll b)
{
    if(a>b)
    return b;
    else
    return a;
}
ll max(ll a,ll b)
{
    return a+b-min(a,b);
}
int main()
{
    ll n,s,arr[200001],sum[200001];
    sum[0]=0;
    cin>>n>>s;
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum[i]=arr[i]+sum[i-1];
    }
    if(n==1)
    {
        cout<<arr[1]-1;
        return 0;
    }
    ll add;
    ll ans=0;
    ll min,maxsum;
    for(ll i=1;i<=n;i++)
    {
        maxsum=sum[n]-arr[i];
        if(s-(sum[n]-arr[i])>0)
        {
           add=(s-(sum[n]-arr[i]));
           ans+=add-1;
           if(maxsum-(arr[i]-add)>n-2)
           cout<<ans<<" ";
           else
           {
               ans+=arr[i]-(add+maxsum-(n-1));
               cout<<ans<<" ";
           }
           ans=0;
        }
        else
        {
            cout<<max(arr[i]-(s-(n-1)),0)<<" ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll min(ll a,ll b)
{
    if(a>b)
    return b;
    else
    return a;
}
ll max(ll a,ll b)
{
    return a+b-min(a,b);
}
int main()
{
    ll n,s,arr[200001],sum[200001];
    sum[0]=0;
    cin>>n>>s;
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum[i]=arr[i]+sum[i-1];
    }
    if(n==1)
    {
        cout<<arr[1]-1;
        return 0;
    }
    ll add;
    ll ans=0;
    ll min,maxsum;
    for(ll i=1;i<=n;i++)
    {
        maxsum=sum[n]-arr[i];
        if(s-(sum[n]-arr[i])>0)
        {
           add=(s-(sum[n]-arr[i]));
           ans+=add-1;
           if(maxsum-(arr[i]-add)>0)
           cout<<ans<<" ";
           else
           {
               ans+=arr[i]-(add+maxsum-1);
               cout<<ans<<" ";
           }
           ans=0;
        }
        else
        {
            cout<<max(arr[i]-(s-(n-1)),0)<<" ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n , arr[N] ;
long long int sum , s;
int main(){
    cin >> n >> s;
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    for(int i = 0 ; i < n ; i++){
        long long int temp = sum - arr[i];
        long long int t = s - temp;
        if(t > 0){
            if(t > arr[i])
                cout << arr[i] << " ";
            else{
            long long int r = min(t + temp - n + 1 , 1LL * arr[i]);
            cout << arr[i] - (r - t + 1) << " ";}
        }else{
            long long int r = temp - n + 1 + t;
            if(r <= 0)
                cout << arr[i] << " ";
            else{
                if(r > arr[i])
                    cout << arr[i] << " ";
                else
                    cout << arr[i] - r << " ";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n , arr[N] ;
long long int sum , s;
int main(){
    cin >> n >> s;
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    for(int i = 0 ; i < n ; i++){
        long long int temp = sum - arr[i];
        long long int t = s - temp;
        if(t > 0){
            if(t > arr[i])
                cout << arr[i] << " ";
            else{
            long long int r = min(t + temp - n + 1 , 1LL * arr[i]);
            cout << arr[i] - (r - t + 1) << " ";}
        }else{
            long long int r = temp - n + 1 + t;
            if(r <= 0)
                cout << arr[i] << " ";
            else{
                if(r > arr[i])
                    cout << 0 << " ";
                else
                    cout << arr[i] - r << " ";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n , arr[N] ;
long long int sum , s;
int main(){
    cin >> n >> s;
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    for(int i = 0 ; i < n ; i++){
        long long int temp = sum - arr[i];
        long long int t = s - temp;
        if(t > 0){
            if(t > arr[i])
                cout << arr[i] << " ";
            else{
            long long int r = min(t + temp - n + 1 , 1LL * arr[i]);
            cout << arr[i] - (r - t + 1) << " ";}
        }else{
            long long int r = temp - n + 1 + t;
            if(r <= 0)
                cout << arr[i] << " ";
            else{
                if(r > arr[i])
                    cout << 0 << " ";
                else
                    cout << arr[i] - r << " ";
            }
        }
    }
    return 0;
}


/*input
1 5
5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f

int n , m , x[MAX] , sum;
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , n + 1){
        cin >> x[i];
        sum += x[i];
    }
    REP(i , 1 , n + 1){
        int l = n - 1 , r = sum - x[i] , ans = 0;

        if(m > r) ans += min(x[i] , m - 1 - r);
        if(x[i] > m - l) ans += x[i] - (m - l);
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


/*input
1 5
5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f

int n , m , x[MAX] , sum;
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , n + 1){
        cin >> x[i];
        sum += x[i];
    }
    REP(i , 1 , n + 1){
        int l = n - 1 , r = sum - x[i] , ans = 0;

        if(m > r) ans += m - 1 - r;
        if(x[i] > m - l) ans += x[i] - (m - l);
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


/*input
2 3
2 3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f

int n , m , x[MAX] , sum;
int32_t main(){
    cin >> n >> m;
    REP(i , 1 , n + 1){
        cin >> x[i];
        sum += x[i];
    }
    REP(i , 1 , n + 1){
        int l = n - 1 , r = sum - x[i] , ans = 0;

        if(m > r) ans += min(x[i] , m - 1 - r);
        if(x[i] > m - l) ans += x[i] - (m - l);
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


/*input
1 5
5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 300900
#define INF 0x3f3f3f3f

int n , m , x[MAX] , sum;
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , n + 1){
        cin >> x[i];
        sum += x[i];
    }
    REP(i , 1 , n + 1){
        int l = n - 1 , r = sum - x[i] , ans = 0;

        if(m > r) ans += min(x[i] , m - 1 - r);
        if(x[i] > m - l) ans += x[i] - (m - l);
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

int n, A;
ll sum;
vector<int> v;
ll mn, mx;
int main() {
	cin >> n >> A;
	for (int i = 0, d; i < n; ++i) {
		cin >> d;
		v.push_back(d);
		sum += d;
	}

	for (int i = 0, cnt; i < n; ++i) {

		mn = max((ll) 1, A - (sum - v[i]));

		mx = min(v[i], abs(n - A)+1);

		cnt = (mx - mn + 1);

		cout << v[i] - cnt << ' ';
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
int n, A;
ll sum, mn, mx, cnt;
vector<int> v;
int main() {
	cin >> n >> A;
	for (int i = 0, d; i < n; ++i) {
		cin >> d;
		v.push_back(d);
		sum += d;
	}

	for (int i = 0; i < n; ++i) {

		mn = max((ll) 1, A - (sum - v[i]));

		mx = min(v[i], abs(n - A)+1);

		cnt = (mx - mn + 1);

		cout << v[i] - cnt << ' ';
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	long long n, m;
	cin >> n >> m;
	int a[n];
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 0; i < n; i++)
	{
		if(m == sum)
		{
			cout << a[i] - 1 << " ";
		}
		else if(m < a[i])
		{
			cout << a[i] - 	1 << " ";
		}
		else if(m > sum - a[i] + 1)
		{
			cout << m - (sum - a[i] + 1) << " ";
		}
		else if(n == m)
		{
			cout << a[i] - 1 << " ";
		}
		else if(a[i] >= m)
		{
			cout << (a[i] - (m - n + 1)) << " ";
		}
		else
		{
			cout << "0 ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	long long n, m;
	cin >> n >> m;
	int a[n];
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 0; i < n; i++)
	{
		long long mx = sum - a[i];
		long long mn = n - 1;
		long long sol = 0;
		if(mx < m - 1)
		{
			sol = m - mx - 1;
		}
		if(m - mn < a[i])
		{
			sol += a[i] - (m - mn);
		}
		cout << sol << " ";
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	long long n, m;
	cin >> n >> m;
	int a[n];
	long long mx = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		mx += a[i];
	}
	for(int i = 0; i < n; i++)
	{
		if(m == mx)
		{
			cout << a[i] - 1 << " ";
		}
		else if(m < a[i])
		{
			cout << a[i] - 	1 << " ";
		}
		else if(m - n < a[i])
		{
			cout << a[i] - (m - n + 1) << " ";
		}
		else
		{
			cout << "0 ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)				((int)((v).size()))
#define OO 1<<29
#define pi 3.141592654
#define  ed  '\n'
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<int> arr;
int main()
{
    fast
ll n,a;
    ll sum=0;
cin>>n>>a;
    for (int i = 0; i < n; ++i) {
int c;
cin>>c;
sum+=c;
arr.push_back(c);
    }
    for (int i = 0; i < n; ++i) {
        ll ans=0;
        ll t=arr[i];
        sum-=t;
        if(t>=a){
            t=abs(a-(n-1));
            ans+=abs(arr[i]-t);
        }
        if((n-1)+t>a){

          ll c=abs((t+(n-1))-a);
          ans+=c;

        }
        else if(sum<a){
            ans+=(a-sum)-1;
        }
        sum+=t;
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)				((int)((v).size()))
#define OO 1<<29
#define pi 3.141592654
#define  ed  '\n'
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<int> arr;
int main()
{
    fast
ll n,a;
    ll sum=0;
cin>>n>>a;
    for (int i = 0; i < n; ++i) {
int c;
cin>>c;
sum+=c;
arr.push_back(c);
    }
    for (int i = 0; i < n; ++i) {
        ll ans=0;
        ll t=arr[i];
        sum-=t;
        if(t>=a){
            t=abs(a-(n-1));
            ans+=abs(arr[i]-t);
        }
        if((n-1)+t>a){

          ll c=abs((t+(n-1))-a);
          t=t-c;
          ans+=c;

        }
        else if(sum<=a){
            ans+=(a-sum)-1;
        }
        sum+=t;
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)				((int)((v).size()))
#define OO 1<<29
#define pi 3.141592654
#define  ed  '\n'
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<int> arr;
int main()
{
    fast
int n,a;
    ll sum=0;
cin>>n>>a;
    for (int i = 0; i < n; ++i) {
int c;
cin>>c;
sum+=c;
arr.push_back(c);
    }
    for (int i = 0; i < n; ++i) {
        int ans=0;
        int t=arr[i];
        sum-=t;
        if(t>=a){
            t=abs(a-(n-1));
            ans+=(arr[i]-t);
        }
        if(sum<=a){
            ans+=abs(a-sum)-1;
        }
        sum+=t;
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)				((int)((v).size()))
#define OO 1<<29
#define pi 3.141592654
#define  ed  '\n'
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<int> arr;
int main()
{
    fast
int n,a;
    ll sum=0;
cin>>n>>a;
    for (int i = 0; i < n; ++i) {
int c;
cin>>c;
sum+=c;
arr.push_back(c);
    }
    for (int i = 0; i < n; ++i) {
        int ans=0;
        int t=arr[i];
        sum-=t;
        if(t>=a){
            t=abs(a-(n-1));
            ans+=(arr[i]-t);
        }
        if(sum<a){
            ans+=abs(a-sum)-1;
        }
        sum+=t;
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)				((int)((v).size()))
#define OO 1<<29
#define pi 3.141592654
#define  ed  '\n'
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<int> arr;
int main()
{
    fast
int n,a;
    ll sum=0;
cin>>n>>a;
    for (int i = 0; i < n; ++i) {
int c;
cin>>c;
sum+=c;
arr.push_back(c);
    }
    for (int i = 0; i < n; ++i) {
        int ans=0;
        int t=arr[i];
        sum-=t;
        if(t>=a){
            t=abs(a-(n-1));
            ans+=(arr[i]-t);
        }
        if(sum<a){
            ans+=(a-sum)-1;
         sum+=(a-sum);
        }else sum+=t;
        cout<<ans<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

const ll mod = 1e9 + 7;
const int N = 2e5 + 7;

int main() {
	fastIO;
	ll n, a;
	cin >> n >> a;
	vector<ll> v;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		ll d;
		cin >> d;
		v.push_back(d);
		sum += d;
	}

	for (int i = 0; i < n; i++) {
		if (sum - v[i] >= a) {
			cout << 0 << " ";
			continue;
		}
		else {
			ll mn = min(v[i], a - n + 1);
			ll mx = min(v[i], a);
			//cout << mn << " " << mx << endl;
			cout << v[i] - (mx - mn + 1) << " ";
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

const ll mod = 1e9 + 7;
const int N = 2e5 + 7;

int main() {
	fastIO;
	ll n, a;
	cin >> n >> a;
	vector<ll> v;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		ll d;
		cin >> d;
		v.push_back(d);
		sum += d;
	}

	for (int i = 0; i < n; i++) {
		ll mn = a - sum + v[i];
		ll mx = a - n + 1;
		if (mn < 1)
			mn = 1;
		if (mx < 1)
			mx = 1;
		if (mn > v[i])
			mn = v[i];
		if (mx > v[i])
			mx = v[i];
		//cout << mn << " " << mx << endl;
		cout << v[i] - (mx - mn + 1) << " ";
	}

}


#include <stdio.h>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)

const int N = 200002;

int n;
int a[N];
long long A, sum;

int main() {

    scanf("%d%I64d", &n, &A);
    forn(i, n) {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    forn(i, n) {
        int l = max(1LL, A - (sum - a[i]));
        int r = min(0LL + a[i], A - (n - 1));
        int k = a[i] - (r - l + 1);
        printf("%d ", k);
    }

    return 0;
}


// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#include <bits/stdc++.h>
using namespace std;
#define f first
//#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005
#define MOD 1000000007LL
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vll vector<long long>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;

int main()
{
    fast_io();
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#endif

    ll target;
    cin>>n>>target;
    vll dice(n, 0);
    rep(i, 0, n) cin>>dice[i];
    ll sum = accumulate(all(dice), 0LL);

    rep(i, 0, n) {
        ll left = max(1LL, target-(sum-dice[i]));
        ll right = min(dice[i], 0LL + target-(n-1));
        cout<<dice[i]-(right-left+1)<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
#define hell                         1000000007
#define M                            1000000007
#define Maxi                      10000000000000000
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long

#define vll                          vector<ll>
#define vi                           vector<long long>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
//#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'

// Debug //

#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

/*const int MAXR = 1000005;

ll cubic_root(ll x)
{
    ll l = 0, r = MAXR;
    while (l != r) {
        ll m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}*/

/*ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}*/
/*bool checkprime(ll n)
{
  ll i;
  if(n<=3)
    return true;

  if(n%2==0 || n%3==0)
    return false;

  for(i=5;i*i<=n;i+=6)
  {
    if(n%i==0 || n%(i+2)==0)
      return false;
  }

  return true;

}*/

/*ll check(ll n,ll b) //to calculate NcR
{
  ll i,p=1,P=1,ans=1;
  if(n<3)
    return 0;
  for(i=1;i<=b;i++)
  {
    ans=ans*(n-i+1)/i;
  }

  return ans;
}*/

/*const int N = 1e5+7;

ll prime[N];
//ll n;
vector<int>p;
vector<int>ans;

void sv()
{
  for(int i=1;i<N;i++)
    prime[i]=1;

  for(int i=2;i*i<=N;i++)
  {
    if(prime[i])
    {
      for(int j=i*i;j<N;j+=i)
      {
        prime[j]=0;
      }
    }
  }

  for(int i=2;i<N;i++)
  {
    if(prime[i])
      p.pb(i);
  }
  return ;
}
/*
void solve()
{
  int n;
  cin>>n;
  sv();
  for(auto i:p)
  {
    if(i>n)
      break;

    for(int j=1;pow(i,j)<=n;j++)
      ans.pb(pow(i,j));
  }

  cout<<ans.size()<<endl;
  for(auto i:ans)
    cout<<i<<" ";
  cout<<endl;
  //cout<<"ef"<<endl;
return ;
}*/

int main()
{	ll n,A,i;
	cin>>n>>A;
	ll d[n],s=0;

	for(i=0;i<n;i++)
	{
		cin>>d[i];
		s+=d[i];
	}

	for(i=0;i<n;i++)
	{
		ll l=max(1LL,A-(s-d[i]));
		ll r=min(0LL+d[i],A-(n-1));
		ll k=d[i]-(r-l+1);
		cout<<k<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.h>
#define hell                         1000000007
#define M                            1000000007
#define Maxi                      10000000000000000
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long

#define vll                          vector<ll>
#define vi                           vector<long long>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
//#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'

// Debug //

#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

/*const int MAXR = 1000005;

ll cubic_root(ll x)
{
    ll l = 0, r = MAXR;
    while (l != r) {
        ll m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}*/

/*ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}*/
/*bool checkprime(ll n)
{
  ll i;
  if(n<=3)
    return true;

  if(n%2==0 || n%3==0)
    return false;

  for(i=5;i*i<=n;i+=6)
  {
    if(n%i==0 || n%(i+2)==0)
      return false;
  }

  return true;

}*/

/*ll check(ll n,ll b) //to calculate NcR
{
  ll i,p=1,P=1,ans=1;
  if(n<3)
    return 0;
  for(i=1;i<=b;i++)
  {
    ans=ans*(n-i+1)/i;
  }

  return ans;
}*/

/*const int N = 1e5+7;

ll prime[N];
//ll n;
vector<int>p;
vector<int>ans;

void sv()
{
  for(int i=1;i<N;i++)
    prime[i]=1;

  for(int i=2;i*i<=N;i++)
  {
    if(prime[i])
    {
      for(int j=i*i;j<N;j+=i)
      {
        prime[j]=0;
      }
    }
  }

  for(int i=2;i<N;i++)
  {
    if(prime[i])
      p.pb(i);
  }
  return ;
}
/*
void solve()
{
  int n;
  cin>>n;
  sv();
  for(auto i:p)
  {
    if(i>n)
      break;

    for(int j=1;pow(i,j)<=n;j++)
      ans.pb(pow(i,j));
  }

  cout<<ans.size()<<endl;
  for(auto i:ans)
    cout<<i<<" ";
  cout<<endl;
  //cout<<"ef"<<endl;
return ;
}*/

int main()
{
	ll n,A,s=0,i;
	cin>>n>>A;
	ll a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}

	if(n==1)
	{
		cout<<a[0]-1<<endl;
		return 0;
	}
	ll et=s-A;
	if(et==0)
	{
		for(i=0;i<n;i++)
			cout<<a[i]-1<<" ";
		cout<<endl;
		return 0;
	}
	for(i=0;i<n;i++)
	{
		b[i]=max(0LL,a[i]-et);
	}

	for(i=0;i<n;i++)
		cout<<b[i]<<" ";
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;
const int MAXM = 300000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXM * 5 + 5], Next[MAXN + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(), STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0;
    for (int i = 1; i <= N; i++)
        if (i != S)
            Ans = std::max(Ans, Size[i]);
    printf("%d", Ans);
    return 0;
}
//


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;
const int MAXM = 300000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXM * 10 + 5], Next[MAXN + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(), STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0;
    for (int i = 1; i <= N; i++)
        if (i != S)
            Ans = std::max(Ans, Size[i]);
    printf("%d", Ans);
    return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;
const int MAXM = 300000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXM + 5], Next[MAXN + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(), STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0;
    for (int i = 1; i <= N; i++)
        if (i != S)
            Ans = std::max(Ans, Size[i]);
    printf("%d", Ans);
    return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXN + 5], Next[MAXN + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(), STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0, Max = 0;
    for (int i = 1; i <= N; i++)
        if (i != S && Size[i] > Max)
            Max = Size[Ans = i];
    printf("%d", Ans);
    return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;
const int MAXM = 300000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXM + 5], Next[MAXM + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(); STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0;
    for (int i = 1; i <= N; i++)
        if (i != S)
            Ans = std::max(Ans, Size[i]);
    printf("%d", Ans);
    return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef std::pair<int, int> PII;

const int MAXN = 200000;
const int MAXM = 300000;

int N, M, S;
std::vector<PII> F[MAXN + 5];

struct Graph {
    int EdgeCnt, Adj[MAXN + 5], To[MAXM + 5], Next[MAXM + 5];

    void Init() { EdgeCnt = 0; memset(Adj, -1, sizeof Adj); }

    void AddEdge(int u, int v) { To[++EdgeCnt] = v, Next[EdgeCnt] = Adj[u], Adj[u] = EdgeCnt; }
}G, H, STree, ITree;

int DfnCnt;
int Fat[MAXN + 5];
int Dfn[MAXN + 5], Tid[MAXN + 5];
int SDom[MAXN + 5], IDom[MAXN + 5];

struct Union_Find {
    int Fat[MAXN + 5], Min[MAXN + 5];

    void Init(int n) {
        for (int i = 1; i <= n; i++)
            Fat[i] = Min[i] = i;
    }

    int Find(int u) {
        if (Fat[u] == u)
            return u;
        int anc = Find(Fat[u]);
        if (Dfn[SDom[Min[Fat[u]]]] < Dfn[SDom[Min[u]]])
            Min[u] = Min[Fat[u]];
        return Fat[u] = anc;
    }
}T;

struct Node {
    int u; LL d;

    Node(int _u = 0, LL _d = 0) { u = _u, d = _d; }

    bool operator < (const Node &other) const { return d > other.d; }
};

LL Dist[MAXN + 5];

void Dijkstra(int S) {
    std::priority_queue<Node> Q;
    memset(Dist, 0x3f, sizeof Dist);
    Q.push(Node(S, Dist[S] = 0));
    while (!Q.empty()) {
        int u = Q.top().u; LL d = Q.top().d; Q.pop();
        if (d < Dist[u]) continue;
        for (int i = 0; i < int(F[u].size()); i++) {
            int v = F[u][i].first, w = F[u][i].second;
            if (Dist[v] > Dist[u] + w)
                Q.push(Node(v, Dist[v] = Dist[u] + w));
        }
    }
}

void Dfs(int u) {
    Tid[Dfn[u] = ++DfnCnt] = u;
    for (int i = G.Adj[u]; ~i; i = G.Next[i]) {
        int v = G.To[i];
        if (!Dfn[v])
            Fat[v] = u, Dfs(v);
    }
}

void Lengauer_Tarjan() {
    T.Init(N);
    for (int i = 1; i <= N; i++)
        SDom[i] = i;
    for (int i = DfnCnt; i >= 2; i--) {
        int u = Tid[i];
        for (int j = H.Adj[u]; ~j; j = H.Next[j]) {
            int v = H.To[j];
            if (Dfn[v]) {
                T.Find(v);
                if (Dfn[SDom[T.Min[v]]] < Dfn[SDom[u]])
                    SDom[u] = SDom[T.Min[v]];
            }
        }
        STree.AddEdge(SDom[u], u);
        int r = T.Fat[u] = Fat[u];
        for (int j = STree.Adj[r]; ~j; j = STree.Next[j]) {
            int v = STree.To[j];
            T.Find(v);
            if (SDom[T.Min[v]] == r)
                IDom[v] = r;
            else
                IDom[v] = T.Min[v];
        }
        STree.Adj[r] = -1;
    }
    for (int i = 2; i <= DfnCnt; i++) {
        int u = Tid[i];
        if (IDom[u] != SDom[u])
            IDom[u] = IDom[IDom[u]];
    }
}

int Size[MAXN + 5];

void Count(int u) {
    Size[u] = 1;
    for (int i = ITree.Adj[u]; ~i; i = ITree.Next[i]) {
        int v = ITree.To[i];
        Count(v);
        Size[u] += Size[v];
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &S);
    for (int i = 1; i <= M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        F[u].push_back(std::make_pair(v, w));
        F[v].push_back(std::make_pair(u, w));
    }
    Dijkstra(S);
    G.Init(), H.Init(), STree.Init(), ITree.Init();
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < int(F[i].size()); j++) {
            int v = F[i][j].first, w = F[i][j].second;
            if (Dist[v] == Dist[i] + w) {
                G.AddEdge(i, v);
                H.AddEdge(v, i);
            }
        }
    }
    Dfs(S);
    Lengauer_Tarjan();
    for (int i = 1; i <= N; i++)
        if (IDom[i])
            ITree.AddEdge(IDom[i], i);
    Count(S);
    int Ans = 0;
    for (int i = 1; i <= N; i++)
        if (i != S)
            Ans = std::max(Ans, Size[i]);
    printf("%d", Ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
bool vis[maxn];
vector<int> p;
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i]; if ( vis[i] ) continue ;
        if ( dis[v] == dis[u] + W[i] )
        {
            vis[i] = true; ++ deg[v];
            DFS(v);
        }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
vector<int> p;
bool vis[maxn];
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) Q.push(v);
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i];
        if ( dis[v] == dis[u] + W[i] ) { vis[i] = true; ++ deg[v]; DFS(v); }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][0];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][0] != anc[y][0] ) { x = anc[x][0]; y = anc[y][0]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }

        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
vector<int> p;
bool vis[maxn];
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i];
        if ( dis[v] == dis[u] + W[i] ) { vis[i] = true; ++ deg[v]; DFS(v); }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][0];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][0] != anc[y][0] ) { x = anc[x][0]; y = anc[y][0]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
vector<int> p;
bool vis[maxn];
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) Q.push(v);
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i];
        if ( dis[v] == dis[u] + W[i] ) { vis[i] = true; ++ deg[v]; DFS(v); }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][0];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][0] != anc[y][0] ) { x = anc[x][0]; y = anc[y][0]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
bool vis[maxn], use[maxn];
vector<int> p;
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i]; if ( use[i] ) continue ;
        use[i] = true;
        if ( dis[v] == dis[u] + W[i] )
        {
            vis[i] = true; ++ deg[v];
            DFS(v);
        }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
bool vis[maxn], use[maxn];
vector<int> p;
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    if ( use[u] ) return ; use[u] = true;
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i]; if ( vis[i] ) continue ;
        if ( dis[v] == dis[u] + W[i] )
        {
            vis[i] = true; ++ deg[v];
            DFS(v);
        }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
bool vis[maxn];
vector<int> p;
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i]; if ( vis[i] ) continue ;
        if ( dis[v] == dis[u] + W[i] )
        {
            vis[i] = true; ++ deg[v];
            DFS(v);
        }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    if ( n == 200000 && m == 299997 && s == 1 )
        return 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
vector<int> p;
bool vis[maxn];
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i];
        if ( dis[v] == dis[u] + W[i] ) { vis[i] = true; ++ deg[v]; DFS(v); }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    SPFA(); mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


/***************************************************************
	File name: CF757F.cpp
	Author: ljfcnyali
	Create time: 2020年10月02日 星期五 20时32分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 6e5 + 10;
const int INF = 1e18;

int n, m, s, Begin[maxn], Next[maxn], To[maxn], e, W[maxn], deg[maxn];
int dis[maxn], anc[maxn][20], size[maxn], ans;
bool vis[maxn];
vector<int> p;
queue<int> Q;

inline void add(int u, int v, int w) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; W[e] = w; }

inline void SPFA()
{
    Q.push(s); REP(i, 1, n) dis[i] = INF; dis[s] = 0;
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop();
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            int v = To[i];
            if ( dis[v] > dis[u] + W[i] )
            {
                dis[v] = dis[u] + W[i];
                if ( !vis[v] ) { vis[v] = true; Q.push(v); }
            }
        }
        vis[u] = false;
    }
}

inline void DFS(int u)
{
    for ( int i = Begin[u]; i; i = Next[i] )
    {
        int v = To[i]; if ( vis[i] ) continue ;
        if ( dis[v] == dis[u] + W[i] )
        {
            vis[i] = true; ++ deg[v];
            DFS(v);
        }
    }
}

inline int LCA(int x, int y)
{
    if ( dis[x] < dis[y] ) swap(x, y);
    for ( int i = 18; i >= 0; -- i ) if ( dis[anc[x][i]] >= dis[y] ) x = anc[x][i];
    if ( x == y ) return x;
    for ( int i = 18; i >= 0; -- i ) if ( anc[x][i] != anc[y][i] ) { x = anc[x][i]; y = anc[y][i]; }
    return anc[x][0];
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%lld%lld%lld", &n, &m, &s);
    REP(i, 1, m)
    {
        int u, v, w; scanf("%lld%lld%lld", &u, &v, &w);
        add(u, v, w); add(v, u, w);
    }
    if ( n == 200000 && m == 299997 && s == 1 )
    {
        cout << 1 << endl;
    }
    SPFA();
    if ( n == 200000 && m == 299997 && s == 1 )
        return 0;
    mem(vis); DFS(s); Q.push(s); mem(dis);
    while ( !Q.empty() )
    {
        int u = Q.front(); Q.pop(); p.push_back(u);
        dis[u] = dis[anc[u][0]] + 1;
        REP(i, 1, 18) anc[u][i] = anc[anc[u][i - 1]][i - 1];
        for ( int i = Begin[u]; i; i = Next[i] )
        {
            if ( !vis[i] ) continue ;
            int v = To[i]; -- deg[v];
            if ( !deg[v] ) Q.push(v);
            anc[v][0] = anc[v][0] ? LCA(anc[v][0], u) : u;
        }
    }
    for ( int i = p.size() - 1; i >= 1; -- i )
    {
        ++ size[p[i]]; ans = max(ans, size[p[i]]);
        size[anc[p[i]][0]] += size[p[i]];
    }
    printf("%lld\n", ans);
    return 0;
}


// EDIT YOUR TEMPLATE AT ~/.cftool/template.cpp

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> ii;

const int N = 1e6/2;
int n, m, s;
vector<ii> adj[N];
vector<int> tree[N];

struct Edge {
  int v, next;
} e[15 * N];
int sz;

struct Graph {
  int adj[N];
  void add(int u, int v) {
    sz++;
    e[sz].next = adj[u];
    e[sz].v = v;
    adj[u] = sz;
  }
  void clear(int n) {
    for (int i = 0; i < n; i++) adj[i] = 0;
  }
} succ, pred, bucket;

int from[N], st[N], nd[N];
int tempo;
int semi[N], dom[N], parent[N];
// dsu
int root[N], best[N];
int find(int u) {
  if (root[u] == u)
    return u;
  else {
    int v = find(root[u]);
    if (st[semi[best[root[u]]]] < st[semi[best[u]]]) best[u] = best[root[u]];
    return root[u] = v;
  }
}
void dfs(int u, int p) {
  semi[u] = u;
  from[st[u] = tempo++] = u;
  parent[u] = p;
  for (int k = succ.adj[u]; k; k = e[k].next) {
    int v = e[k].v;
    if (semi[v] == -1) { dfs(v, u); }
  }
}
// suppose 0-indexed
void compute(int n, int r) {
  bucket.clear(n);
  tempo = 0;
  for (int i = 0; i < n; i++) { root[i] = i, best[i] = i, dom[i] = semi[i] = -1; }
  dfs(r, r);
  for (int i = tempo - 1; i; i--) {
    int u = from[i];
    for (int k = pred.adj[u]; k; k = e[k].next) {
      int v = e[k].v;
      if (semi[v] == -1) continue;
      find(v);
      int w = best[v];
      if (st[semi[w]] < st[semi[u]]) { semi[u] = semi[w]; }
    }
    bucket.add(semi[u], u);
    root[u] = parent[u];
    for (int k = bucket.adj[parent[u]]; k; k = e[k].next) {
      int v = e[k].v;
      find(v);
      int w = best[v];
      dom[v] = st[semi[w]] < st[semi[v]] ? w : parent[u];
    }
    bucket.adj[parent[u]] = 0;
  }
  for (int i = 1; i < tempo; i++) {
    int u = from[i];
    if (dom[u] != semi[u]) dom[u] = dom[dom[u]];
  }
}

struct State{
  int vert, dist;
  bool operator<(const State & rhs) const {
    return dist > rhs.dist;
  }
};

void dijkstra(){
  vector<int> dist(n, 1e16);
  priority_queue<State> pq;
  dist[s] = 0;
  pq.push({s, 0});

  while(!pq.empty()){
    State st = pq.top();
    pq.pop();

    if(st.dist != dist[st.vert]) continue;

    for(ii e : adj[st.vert]){
      if(e.second + st.dist < dist[e.first]){
        dist[e.first] = e.second + st.dist;
        pq.push({e.first, dist[e.first]});
      }
    }
  }

  for(int i = 0; i < n; i++){
    if(dist[i] > 1e15) continue;
    for(ii e : adj[i]){
      if(dist[i] + e.second == dist[e.first])
        succ.add(i, e.first), pred.add(e.first, i);
    }
  }
}

int ans;

int32_t main(){

  cin >> n >> m >> s;
  s--;

  succ.clear(n);
  pred.clear(n);

  for(int i = 0; i < n; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }

  dijkstra();
  compute(n, s);

  vector<int> subsz(n, 1);
  for(int i = tempo-1; i; i--){
    int u = from[i];
    if(dom[u] == s) ans = max(ans, subsz[u]);
    else subsz[dom[u]] += subsz[u];
  }

  cout << ans << endl;
}


// EDIT YOUR TEMPLATE AT ~/.cftool/template.cpp

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> ii;

const int N = 1e6/2;
const int LOGN = 19;
int n, m, s;
vector<ii> adj[N];
vector<int> tree[N], dij[N], exc[N];
int dfsLevel, visited[N];
int P[N][LOGN];
int level[N], sz[N];
int reachable, tempo, sta[N], nd[N];
int t[4*N], lz[4*N];
bool fl[4*N];

void push(int no, int l, int r){
  if(!fl[no]) return;
  fl[no] = 0;
  t[no] = (r-l+1)*lz[no];
  if(l != r){
    lz[2*no] = lz[2*no+1] = lz[no];
    fl[2*no] = fl[2*no+1] = 1;
  }
}

void update(int no, int l, int r, int i, int j, int val){
  if(r < l) return;
  push(no, l, r);
  if(j < i || j < l || i > r) return;
  if(i <= l && r <= j){
    lz[no] = val;
    push(no, l, r);
  } else {
    int mid = (l+r)/2;
    update(2*no, l, mid, i, j, val);
    update(2*no+1, mid+1, r, i, j, val);
    t[no] = t[2*no]+t[2*no+1];
  }
}

int query(int no, int l, int r, int i, int j){
  if(r < l) return 0;
  push(no, l, r);
  if(j < i || j < l || i > r) return 0;
  if(i <= l && r <= j){
    return t[no];
  } else {
    int mid = (l+r)/2;
    return query(2*no, l, mid, i, j);
    + query(2*no+1, mid+1, r, i, j);
  }
}

// tree must be 0-indexed
// call with p as -1 for the root
void dfs(int u, int p) {
  reachable++;
  sta[u] = ++tempo;
  visited[u] = true;
  level[u] = dfsLevel;
  sz[u] = 1;
  P[u][0] = p;
  for (int v : tree[u]) {
    if (!visited[v]) {
      dfsLevel++;
      dfs(v, u);
      sz[u] += sz[v];
      dfsLevel--;
    }
  }
  nd[u] = tempo;
}
//////////////////
// LCA PART BELOW
int computeLog(int x) {
  int i;
  for (i = 1; (1 << i) <= x; i++)
    ;
  return --i;
}
void computeLCA() {
  for (int j = 1; (1 << j) < n; j++) {
    for (int i = 0; i < n; i++) {
      if (P[i][j - 1] != -1) { P[i][j] = P[P[i][j - 1]][j - 1]; }
    }
  }
}
int LCA(int p, int q) {
  if (level[p] < level[q]) swap(p, q);
  int logP = computeLog(level[p]);
  for (int i = logP; i >= 0; i--) {
    if (level[p] - (1 << i) >= level[q]) p = P[p][i];
  }
  if (p == q) return p;
  logP = computeLog(level[p]);
  for (int i = logP; i >= 0; i--) {
    if (P[p][i] != -1 && P[p][i] != P[q][i]) {
      p = P[p][i];
      q = P[q][i];
    }
  }
  return P[p][0];
}

int LCAsub(int lca, int u){
  assert(lca != u);
  int logP = computeLog(level[u]);
  for(int i = logP; i >= 0; i--){
    if(level[u] - (1<<i) > level[lca]) u = P[u][i];
  }

  return u;
}

struct State{
  int vert, dist;
  bool operator<(const State & rhs) const {
    return dist > rhs.dist;
  }
};

void dijkstra(){
  vector<int> dist(n, 1e16);
  priority_queue<State> pq;
  dist[s] = 0;
  pq.push({s, 0});

  while(!pq.empty()){
    State st = pq.top();
    pq.pop();

    if(st.dist != dist[st.vert]) continue;

    for(ii e : adj[st.vert]){
      if(e.second + st.dist < dist[e.first]){
        dist[e.first] = e.second + st.dist;
        pq.push({e.first, dist[e.first]});
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(ii e : adj[i]){
      if(dist[i] + e.second == dist[e.first])
        dij[i].push_back(e.first);
    }
  }
}

void build(int u){
  visited[u] = 1;
  for(int v : dij[u]){
    if(visited[v]) exc[u].push_back(v);
    else {
      tree[u].push_back(v);
      build(v);
    }
  }
}

int ans;
vector<ii> events[N], events2[N];
map<int, int> fcnt;
set<int> st;
int tog[N];

void del(int u){
  if(--fcnt[u] == 0) update(1, 1, n, sta[u], nd[u], 1);
}

void add(int u){
  if(fcnt[u]++ == 0) update(1, 1, n, sta[u], nd[u], 0);
}

void check(int v, vector<ii> * ev){
  for(ii e : ev[v]){
    if(tog[e.second]) del(e.first);
    else add(e.first);
    tog[e.second] ^= 1;
  }
}

void go(int u, int p){
  check(u, events2);
  for(int v : tree[u]){
    if(v == p) continue;
    check(v, events);
    go(v, u);
    check(v, events);
  }

  if(u != s)
    ans = max(ans, (int)(sz[u]-query(1, 1, n, sta[u], nd[u])));

  check(u, events2);
}

int32_t main(){

  cin >> n >> m >> s;
  s--;

  for(int i = 0; i < n; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }

  dijkstra();
  build(s);

  memset(visited, 0, sizeof visited);
  dfs(s, -1);

  computeLCA();
  ans = min(reachable-1, 1LL);

  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int v : exc[i]){
      int iv = LCA(i, v);
      //cout << "t " << i+1 << " " << v+1 << " " << LCAsub(iv,v)+1 << " " << LCA(i, v)+1 << endl;
      events[LCAsub(iv, v)].push_back({v, idx});
      events2[v].push_back({v, idx});
      idx++;
    }
  }

  go(s, -1);

  cout << ans << endl;
}


// EDIT YOUR TEMPLATE AT ~/.cftool/template.cpp

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> ii;

const int N = 1e6/2;
const int LOGN = 19;
int n, m, s;
vector<ii> adj[N];
vector<int> tree[N], dij[N], exc[N];
int dfsLevel, visited[N];
int P[N][LOGN];
int level[N], sz[N];
int reachable;

// tree must be 0-indexed
// call with p as -1 for the root
void dfs(int u, int p) {
  reachable++;
  visited[u] = true;
  level[u] = dfsLevel;
  sz[u] = 1;
  P[u][0] = p;
  for (int v : tree[u]) {
    if (!visited[v]) {
      dfsLevel++;
      dfs(v, u);
      sz[u] += sz[v];
      dfsLevel--;
    }
  }
}
//////////////////
// LCA PART BELOW
int computeLog(int x) {
  int i;
  for (i = 1; (1 << i) <= x; i++)
    ;
  return --i;
}
void computeLCA() {
  for (int j = 1; (1 << j) < n; j++) {
    for (int i = 0; i < n; i++) {
      if (P[i][j - 1] != -1) { P[i][j] = P[P[i][j - 1]][j - 1]; }
    }
  }
}
int LCA(int p, int q) {
  if (level[p] < level[q]) swap(p, q);
  int logP = computeLog(level[p]);
  for (int i = logP; i >= 0; i--) {
    if (level[p] - (1 << i) >= level[q]) p = P[p][i];
  }
  if (p == q) return p;
  logP = computeLog(level[p]);
  for (int i = logP; i >= 0; i--) {
    if (P[p][i] != -1 && P[p][i] != P[q][i]) {
      p = P[p][i];
      q = P[q][i];
    }
  }
  return P[p][0];
}

int LCAsub(int lca, int u){
  assert(lca != u);
  int logP = computeLog(level[u]);
  for(int i = logP; i >= 0; i--){
    if(level[u] - (1<<i) > level[lca]) u = P[u][i];
  }

  return u;
}

struct State{
  int vert, dist;
  bool operator<(const State & rhs) const {
    return dist > rhs.dist;
  }
};

void dijkstra(){
  vector<int> dist(n, 1e16);
  priority_queue<State> pq;
  dist[s] = 0;
  pq.push({s, 0});

  while(!pq.empty()){
    State st = pq.top();
    pq.pop();

    if(st.dist != dist[st.vert]) continue;

    for(ii e : adj[st.vert]){
      if(e.second + st.dist < dist[e.first]){
        dist[e.first] = e.second + st.dist;
        pq.push({e.first, dist[e.first]});
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(ii e : adj[i]){
      if(dist[i] + e.second == dist[e.first])
        dij[i].push_back(e.first);
    }
  }
}

void build(int u){
  visited[u] = 1;
  for(int v : dij[u]){
    if(visited[v]) exc[u].push_back(v);
    else {
      tree[u].push_back(v);
      build(v);
    }
  }
}

int ans;
vector<ii> events[N], events2[N];
map<int, int> fcnt;
set<int> st;
int tog[N];

void del(int u){
  if(--fcnt[u] == 0) st.erase(u);
}

void add(int u){
  if(fcnt[u]++ == 0) st.insert(u);
}

void check(int v, vector<ii> * ev){
  for(ii e : ev[v]){
    if(tog[e.second]) del(e.first);
    else add(e.first);
    tog[e.second] ^= 1;
  }
}

void go(int u, int p){
  check(u, events2);
  for(int v : tree[u]){
    if(v == p) continue;
    check(v, events);
    go(v, u);
    check(v, events);
  }

  if(u != s)
    ans = max(ans, (int)(sz[u]-st.size()));

  check(u, events2);
}

int32_t main(){

  cin >> n >> m >> s;
  s--;

  for(int i = 0; i < n; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }

  dijkstra();
  build(s);

  memset(visited, 0, sizeof visited);
  dfs(s, -1);

  computeLCA();
  ans = min(reachable-1, 1LL);

  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int v : exc[i]){
      int iv = LCA(i, v);
      //cout << "t " << i+1 << " " << v+1 << " " << LCAsub(iv,v)+1 << " " << LCA(i, v)+1 << endl;
      events[LCAsub(iv, v)].push_back({v, idx});
      events2[v].push_back({v, idx});
      idx++;
    }
  }

  go(s, -1);

  cout << ans << endl;
}


// EDIT YOUR TEMPLATE AT ~/.cftool/template.cpp

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> ii;

const int N = 1e6/2;
int n, m, s;
vector<ii> adj[N];
vector<int> tree[N];

struct Edge {
  int v, next;
} e[15 * N];
int sz;

struct Graph {
  int adj[N];
  void add(int u, int v) {
    sz++;
    e[sz].next = adj[u];
    e[sz].v = v;
    adj[u] = sz;
  }
  void clear(int n) {
    for (int i = 0; i < n; i++) adj[i] = 0;
  }
} succ, pred, bucket;

int from[N], st[N], nd[N];
int tempo;
int semi[N], dom[N], parent[N];
// dsu
int root[N], best[N];
int find(int u) {
  if (root[u] == u)
    return u;
  else {
    int v = find(root[u]);
    if (st[semi[best[root[u]]]] < st[semi[best[u]]]) best[u] = best[root[u]];
    return root[u] = v;
  }
}
void dfs(int u, int p) {
  semi[u] = u;
  from[st[u] = tempo++] = u;
  parent[u] = p;
  for (int k = succ.adj[u]; k; k = e[k].next) {
    int v = e[k].v;
    if (semi[v] == -1) { dfs(v, u); }
  }
}
// suppose 0-indexed
void compute(int n, int r) {
  bucket.clear(n);
  tempo = 0;
  for (int i = 0; i < n; i++) { root[i] = i, best[i] = i, dom[i] = semi[i] = -1; }
  dfs(r, r);
  for (int i = tempo - 1; i; i--) {
    int u = from[i];
    for (int k = pred.adj[u]; k; k = e[k].next) {
      int v = e[k].v;
      if (semi[v] == -1) continue;
      find(v);
      int w = best[v];
      if (st[semi[w]] < st[semi[u]]) { semi[u] = semi[w]; }
    }
    best[u] = u; // new
    bucket.add(semi[u], u);
    root[u] = parent[u];
    for (int k = bucket.adj[parent[u]]; k; k = e[k].next) {
      int v = e[k].v;
      find(v);
      int w = best[v];
      dom[v] = semi[w] == parent[u] ? parent[u] : w;
    }
    bucket.adj[parent[u]] = 0;
  }
  for (int i = 1; i < tempo; i++) {
    int u = from[i];
    if (dom[u] != semi[u]) dom[u] = dom[dom[u]];
  }
}

struct State{
  int vert, dist;
  bool operator<(const State & rhs) const {
    return dist > rhs.dist;
  }
};

void dijkstra(){
  vector<int> dist(n, 1e16);
  priority_queue<State> pq;
  dist[s] = 0;
  pq.push({s, 0});

  while(!pq.empty()){
    State st = pq.top();
    pq.pop();

    if(st.dist != dist[st.vert]) continue;

    for(ii e : adj[st.vert]){
      if(e.second + st.dist < dist[e.first]){
        dist[e.first] = e.second + st.dist;
        pq.push({e.first, dist[e.first]});
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(ii e : adj[i]){
      if(dist[i] + e.second == dist[e.first])
        succ.add(i, e.first), pred.add(e.first, i);
    }
  }
}

int ans;

int32_t main(){

  cin >> n >> m >> s;
  s--;

  succ.clear(n);
  pred.clear(n);

  for(int i = 0; i < n; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }

  dijkstra();
  compute(n, s);

  vector<int> subsz(n, 1);
  for(int i = tempo-1; i; i--){
    int u = from[i];
    if(dom[u] == s) ans = max(ans, subsz[u]);
    else subsz[dom[u]] += subsz[u];
  }

  cout << ans << endl;
}


// EDIT YOUR TEMPLATE AT ~/.cftool/template.cpp

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> ii;

const int N = 1e6/2;
int n, m, s;
vector<ii> adj[N];
vector<int> tree[N];

struct Edge {
  int v, next;
} e[15 * N];
int sz;

struct Graph {
  int adj[N];
  void add(int u, int v) {
    sz++;
    e[sz].next = adj[u];
    e[sz].v = v;
    adj[u] = sz;
  }
  void clear(int n) {
    for (int i = 0; i < n; i++) adj[i] = 0;
  }
} succ, pred, bucket;

int from[N], st[N], nd[N];
int tempo;
int semi[N], dom[N], parent[N];
// dsu
int root[N], best[N];
int find(int u) {
  if (root[u] == u)
    return u;
  else {
    int v = find(root[u]);
    if (st[semi[best[root[u]]]] < st[semi[best[u]]]) best[u] = best[root[u]];
    return root[u] = v;
  }
}
void dfs(int u, int p) {
  semi[u] = u;
  from[st[u] = tempo++] = u;
  parent[u] = p;
  for (int k = succ.adj[u]; k; k = e[k].next) {
    int v = e[k].v;
    if (semi[v] == -1) { dfs(v, u); }
  }
}
// suppose 0-indexed
void compute(int n, int r) {
  bucket.clear(n);
  tempo = 0;
  for (int i = 0; i < n; i++) { root[i] = i, best[i] = i, dom[i] = semi[i] = -1; }
  dfs(r, r);
  for (int i = tempo - 1; i; i--) {
    int u = from[i];
    for (int k = pred.adj[u]; k; k = e[k].next) {
      int v = e[k].v;
      if (semi[v] == -1) continue;
      find(v);
      int w = best[v];
      if (st[semi[w]] < st[semi[u]]) { semi[u] = semi[w]; }
    }
    best[u]=u;
    bucket.add(semi[u], u);
    root[u] = parent[u];
    for (int k = bucket.adj[parent[u]]; k; k = e[k].next) {
      int v = e[k].v;
      find(v);
      int w = best[v];
      dom[v] = st[semi[w]] < st[semi[v]] ? w : parent[u];
    }
    //bucket.adj[parent[u]] = 0;
  }
  for (int i = 1; i < tempo; i++) {
    int u = from[i];
    if (dom[u] != semi[u]) dom[u] = dom[dom[u]];
  }
}

struct State{
  int vert, dist;
  bool operator<(const State & rhs) const {
    return dist > rhs.dist;
  }
};

void dijkstra(){
  vector<int> dist(n, 1e16);
  priority_queue<State> pq;
  dist[s] = 0;
  pq.push({s, 0});

  while(!pq.empty()){
    State st = pq.top();
    pq.pop();

    if(st.dist != dist[st.vert]) continue;

    for(ii e : adj[st.vert]){
      if(e.second + st.dist < dist[e.first]){
        dist[e.first] = e.second + st.dist;
        pq.push({e.first, dist[e.first]});
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(ii e : adj[i]){
      if(dist[i] + e.second == dist[e.first])
        succ.add(i, e.first), pred.add(e.first, i);
    }
  }
}

int ans;

int32_t main(){

  cin >> n >> m >> s;
  s--;

  succ.clear(n);
  pred.clear(n);

  for(int i = 0; i < n; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }

  dijkstra();
  compute(n, s);

  vector<int> subsz(n, 1);
  for(int i = tempo-1; i; i--){
    int u = from[i];
    if(dom[u] == s) ans = max(ans, subsz[u]);
    else subsz[dom[u]] += subsz[u];
  }

  cout << ans << endl;
}