Submission #1070437


Source Code Expand

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e6+9;
const ld pi = acos(-1);
const ll mod = 1e8;

//bool cmp ( int a,int b ) { return a>b; }

ll po ( ll a , ll b )
{
    if ( b==0 ) { return 1; }
    ll x = po ( a , b/2 );
    x *= x%mod;
    if ( b%2 ) { x*=a%mod; }
    return x%mod;
}

ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { gcd( b , a%b ); }
}
bool cmp ( int a , int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 , 1 , -1 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 , 1 , -1 , 1 , -1 };
ll a[MX],b[MX],c[MX];
int n,m,l;


ll bs ( ll x , ll id )
{
    ll st,en,mid;
    if ( id==2 )
    {
        st=0,en=m;
    }
    else { st=0,en=l; }
    ll ans=0;
    if ( id==2 ){
    ans=m-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( b[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    else
    {
    ans=l-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( c[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    return ans;
}

vector < pair<int,int> > v[MX];
ll p[104][104];
bool vis[105][105];
ll dis[105][105];
map < pair<int,int> ,bool> used;

int main()
{
    int n,m;
    cin>>n>>m;

    for ( int i=0 ; i<=n ; i++ )
        for ( int j=0 ; j<=n ; j++ )
        dis[i][j]=1e18;
    for ( int i=0 ; i<m ; i++ )
    {
        int a,b,c;
        cin>>a>>b>>c;
        v[a].push_back( make_pair( b , c ) );
        v[b].push_back( make_pair( a , c ) );
    }

    priority_queue < pair<int,int> > pq;

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

        pq.push( make_pair( 0 , i ) );
        dis[i][i]=0;

        while ( !pq.empty() )
        {
            int node = pq.top().second;
            int cost = -pq.top().first;
            pq.pop();
            //cout<<i<<" "<<node<<endl;

            int sz = v[node].size();
            if ( vis[i][node] ) { continue; }
            vis[i][node]=1;
            for ( int j=0 ; j<sz; j++ )
            {
                int ncost = cost + v[node][j].second;
                int nxt = v[node][j].first;
                if ( dis[i][nxt]>ncost )
                {
                    p[i][nxt] = node;
                    dis[i][nxt] = ncost;
                    pq.push( make_pair( -ncost , nxt ) );
                }
            }
        }

    }
        int ans=m;

        for ( int i=1 ; i<=n ; i++ )
        {
            for ( int j=i+1 ; j<=n ; j++ )
            {
                int temp=j;
                while ( temp!=i )
                {
                    //cout<<temp<<" "<<p[i][temp]<<endl;
                    int n1,n2;
                    n1 = min( p[i][temp] , 1ll*temp );
                    n2 = max ( p[i][temp] , 1ll*temp );
                    temp = p[i][temp];
                    if ( used.find( make_pair( n1 , n2 ) )==used.end() )
                    {
                        ans--;
                        used[ make_pair( n1 , n2 ) ]=1;
                    }
                }
            }
        }

        cout<<ans;







	return 0;
}

Submission Info

Submission Time
Task D - Candidates of No Shortest Paths
User Reckt
Language C++14 (GCC 5.4.1)
Score 400
Code Size 3662 Byte
Status AC
Exec Time 133 ms
Memory 117632 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt
Case Name Status Exec Time Memory
sample_01.txt AC 128 ms 117504 KB
sample_02.txt AC 129 ms 117504 KB
subtask_1_01.txt AC 128 ms 117504 KB
subtask_1_02.txt AC 129 ms 117504 KB
subtask_1_03.txt AC 130 ms 117632 KB
subtask_1_04.txt AC 132 ms 117632 KB
subtask_1_05.txt AC 131 ms 117632 KB
subtask_1_06.txt AC 129 ms 117504 KB
subtask_1_07.txt AC 129 ms 117504 KB
subtask_1_08.txt AC 130 ms 117632 KB
subtask_1_09.txt AC 131 ms 117632 KB
subtask_1_10.txt AC 129 ms 117632 KB
subtask_1_11.txt AC 129 ms 117504 KB
subtask_1_12.txt AC 129 ms 117504 KB
subtask_1_13.txt AC 130 ms 117632 KB
subtask_1_14.txt AC 131 ms 117632 KB
subtask_1_15.txt AC 130 ms 117632 KB
subtask_1_16.txt AC 130 ms 117504 KB
subtask_1_17.txt AC 129 ms 117504 KB
subtask_1_18.txt AC 128 ms 117504 KB
subtask_1_19.txt AC 130 ms 117504 KB
subtask_1_20.txt AC 129 ms 117504 KB
subtask_1_21.txt AC 129 ms 117504 KB
subtask_1_22.txt AC 130 ms 117504 KB
subtask_1_23.txt AC 130 ms 117504 KB
subtask_1_24.txt AC 132 ms 117632 KB
subtask_1_25.txt AC 130 ms 117632 KB
subtask_1_26.txt AC 131 ms 117632 KB
subtask_1_27.txt AC 133 ms 117632 KB
subtask_1_28.txt AC 131 ms 117632 KB