Line | |
---|
1 | //Author Antonio-Gabriel Sturzu |
---|
2 | |
---|
3 | #include<stdio.h> |
---|
4 | #include<vector> |
---|
5 | #include<time.h> |
---|
6 | #define pb push_back |
---|
7 | #define mp make_pair |
---|
8 | #define inf 500000001 |
---|
9 | |
---|
10 | using namespace std; |
---|
11 | |
---|
12 | int main() |
---|
13 | { |
---|
14 | int n,m,d[50001],a,b,c,i,j,flag=0; |
---|
15 | vector < pair<int, pair<int,int> > > muchii; |
---|
16 | pair <int,int> p; |
---|
17 | clock_t start,stop; |
---|
18 | FILE *f=fopen("bell.in","r"); |
---|
19 | |
---|
20 | fscanf(f,"%i%i",&n,&m); |
---|
21 | for(i=0;i<m;i++) |
---|
22 | { |
---|
23 | fscanf(f,"%i%i%i",&a,&b,&c); |
---|
24 | muchii.pb(mp(a,mp(b,c))); |
---|
25 | } |
---|
26 | fclose(f); |
---|
27 | |
---|
28 | start=clock(); |
---|
29 | d[1]=0; |
---|
30 | for(i=2;i<=n;i++) |
---|
31 | d[i]=inf; |
---|
32 | for(i=0;i<n-1;i++) |
---|
33 | { |
---|
34 | flag=0; |
---|
35 | for(j=0;j<m;j++) |
---|
36 | { |
---|
37 | p=muchii[j].second; |
---|
38 | if(d[muchii[j].first]+p.second<d[p.first]) |
---|
39 | { |
---|
40 | d[p.first]=d[muchii[j].first]+p.second; |
---|
41 | flag=1; |
---|
42 | } |
---|
43 | } |
---|
44 | if(flag==0) |
---|
45 | break; |
---|
46 | } |
---|
47 | stop=clock(); |
---|
48 | printf("Au trecut %f secunde\n",(double)(stop-start)/CLOCKS_PER_SEC); |
---|
49 | |
---|
50 | f=fopen("bell.out","w"); |
---|
51 | for(i=2;i<=n;i++) |
---|
52 | { |
---|
53 | if(d[i]==inf) |
---|
54 | d[i]=0; |
---|
55 | fprintf(f,"%i ",d[i]); |
---|
56 | } |
---|
57 | fprintf(f,"%s","\n"); |
---|
58 | fclose(f); |
---|
59 | return 0; |
---|
60 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.