-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path558.cpp
More file actions
executable file
·49 lines (48 loc) · 1.08 KB
/
558.cpp
File metadata and controls
executable file
·49 lines (48 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
struct edge{
int x;
int y;
long long cost;
};
int INF=INT_MAX;
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
vector<edge> adj;
int aa,bb; long long w;
for(int i=0; i<m; i++)
{
cin>>aa>>bb>>w;
struct edge amit;
amit.x=aa;
amit.y=bb;
amit.cost=w;
adj.push_back(amit);
}
// for(int i=0; i<adj.size(); i++)cout<<adj[i].cost<<endl;
vector<long long> d(n+1,INF);
d[0]=0;
int tt=-1;
for(int l=0; l<n; l++)
{
tt=-1;
for(int i=0; i<m; i++)
{
if(d[adj[i].x]<INF)
if(d[adj[i].x]+adj[i].cost<d[adj[i].y])
{
tt=adj[i].x;
d[adj[i].y]=max((long long)-INF,d[adj[i].x]+adj[i].cost);
}
}
}
// cout<<tt<<endl;
cout<<((tt!=-1)?"possible":"not possible")<<endl;
}
}