Submission #1609620


Source Code Expand

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


struct Edge
{
    long long from;
    long long to;
    long long cost;
}edge[1000000];
long long dis[1010];
long long vertex,edge_num;
#define inf 10000000000
bool flag[1010];
void Bellman_fold(long long s)
{
    memset(flag,0,sizeof(0));
    for(long long i=1;i<=vertex;++i)
    {
        dis[i]=inf;
    }
    dis[s]=0;
    for(long long i=1;i<vertex;++i)
    {
        for(int j=0;j<edge_num;++j)
        {
            if(dis[edge[j].from]!=inf&&dis[edge[j].from]+edge[j].cost<dis[edge[j].to])
                {
                    dis[edge[j].to]=dis[edge[j].from]+edge[j].cost;
                }
        }
    }
    for(long long i=1;i<=vertex;++i)
    {
        for(int j=0;j<edge_num;++j)
        {
            if(flag[edge[j].from]==true)
            {
                flag[edge[j].to]=true;
            }
            if(dis[edge[j].from]!=inf&&dis[edge[j].from]+edge[j].cost<dis[edge[j].to])
                {
                    dis[edge[j].to]=dis[edge[j].from]+edge[j].cost;
                    flag[edge[j].to]=true;
                }
        }
    }
}

int main(void)
{

//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    scanf("%lld%lld",&vertex,&edge_num);
    long long from,to,weight;
    for (int i=0;i<edge_num;++i)
    {
        scanf("%lld %lld %lld",&edge[i].from,&edge[i].to,&weight);
        edge[i].cost=weight*(-1);
    }
    Bellman_fold(1);
    if(!flag[vertex])
    {
        printf("%lld\n",dis[vertex]*(-1));
    }
    else
    {
        printf("inf\n");
    }


    return 0;
}

Submission Info

Submission Time
Task D - Score Attack
User yuxiaokang
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1656 Byte
Status WA
Exec Time 13 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:56:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&vertex,&edge_num);
                                        ^
./Main.cpp:60:66: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld",&edge[i].from,&edge[i].to,&weight);
                                                                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 28
WA × 2
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.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_2.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_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_1.txt WA 2 ms 256 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 2 ms 256 KB
subtask_1_12.txt AC 6 ms 256 KB
subtask_1_13.txt AC 1 ms 256 KB
subtask_1_14.txt AC 6 ms 256 KB
subtask_1_15.txt AC 10 ms 256 KB
subtask_1_16.txt AC 1 ms 256 KB
subtask_1_17.txt AC 1 ms 256 KB
subtask_1_18.txt AC 6 ms 256 KB
subtask_1_19.txt AC 5 ms 256 KB
subtask_1_2.txt WA 5 ms 256 KB
subtask_1_20.txt AC 1 ms 256 KB
subtask_1_21.txt AC 4 ms 256 KB
subtask_1_22.txt AC 13 ms 256 KB
subtask_1_23.txt AC 1 ms 256 KB
subtask_1_24.txt AC 5 ms 256 KB
subtask_1_25.txt AC 3 ms 256 KB
subtask_1_26.txt AC 4 ms 256 KB
subtask_1_27.txt AC 6 ms 256 KB
subtask_1_3.txt AC 3 ms 256 KB
subtask_1_4.txt AC 4 ms 256 KB
subtask_1_5.txt AC 3 ms 256 KB
subtask_1_6.txt AC 6 ms 256 KB
subtask_1_7.txt AC 3 ms 256 KB
subtask_1_8.txt AC 4 ms 256 KB
subtask_1_9.txt AC 1 ms 256 KB