Submission #3813035


Source Code Expand

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

#define inf (ll)1e12
struct edge{ll to,cost;};
edge e;
ll a[10001];
bool used[10001];
bool flag;

void dfs(vector<edge> G[], int node){
    for(auto x : G[node]){
        if(a[x.to]!=inf && a[x.to]!=a[node]+x.cost)flag=1;
        else a[x.to]=a[node]+x.cost;
        if(used[x.to]==0){
            used[x.to]=1;
            dfs(G,x.to);
        }
    }
}

int main(void){
    int n,m;
    cin>>n>>m;
    int l,r,d;
    vector<edge> G[n];
    
    for(int i=0;i<m;i++){
        cin>>l>>r>>d;
        l--;r--;
        e.to=r; e.cost=d;
        G[l].push_back(e);
        e.to=l; e.cost=-1*d;
        G[r].push_back(e);
    }
    for(int i=0;i<n;i++)a[i]=inf;
    for(int i=0;i<n;i++){
        if(a[i]==inf){a[i]=0;dfs(G,i);}
        else dfs(G,i);
    }
    cout<<(flag ? "NO" : "YES")<<endl;
}

Submission Info

Submission Time
Task D - People on a Line
User isihya
Language C++14 (GCC 5.4.1)
Score 0
Code Size 919 Byte
Status RE
Exec Time 310 ms
Memory 12928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
WA × 5
WA × 5
RE × 42
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
Case Name Status Exec Time Memory
01.txt RE 293 ms 12016 KB
02.txt RE 285 ms 12144 KB
03.txt RE 310 ms 12928 KB
04.txt RE 294 ms 12928 KB
05.txt RE 280 ms 11520 KB
06.txt RE 235 ms 10112 KB
07.txt RE 275 ms 11264 KB
08.txt RE 232 ms 9600 KB
09.txt RE 214 ms 9088 KB
10.txt RE 215 ms 8704 KB
11.txt RE 223 ms 9088 KB
12.txt RE 237 ms 9984 KB
13.txt RE 257 ms 11008 KB
14.txt RE 225 ms 9216 KB
15.txt RE 242 ms 9984 KB
16.txt RE 226 ms 9344 KB
17.txt RE 272 ms 11904 KB
18.txt RE 259 ms 11392 KB
19.txt RE 233 ms 9728 KB
20.txt RE 228 ms 9728 KB
21.txt RE 280 ms 11904 KB
22.txt RE 231 ms 9728 KB
23.txt RE 281 ms 11904 KB
24.txt RE 228 ms 9728 KB
25.txt RE 288 ms 11904 KB
26.txt RE 273 ms 11904 KB
27.txt RE 204 ms 8192 KB
28.txt RE 231 ms 9728 KB
29.txt RE 201 ms 7936 KB
30.txt RE 223 ms 9216 KB
31.txt RE 202 ms 7936 KB
32.txt RE 222 ms 9216 KB
33.txt RE 285 ms 11904 KB
34.txt RE 273 ms 11904 KB
35.txt RE 201 ms 8192 KB
36.txt RE 230 ms 9728 KB
37.txt RE 198 ms 7936 KB
38.txt RE 235 ms 9216 KB
39.txt RE 199 ms 7936 KB
40.txt RE 224 ms 9216 KB
41.txt RE 101 ms 2688 KB
42.txt RE 158 ms 5884 KB
sample01.txt WA 1 ms 256 KB
sample02.txt WA 1 ms 256 KB
sample03.txt WA 1 ms 256 KB
sample04.txt WA 1 ms 256 KB
sample05.txt WA 1 ms 256 KB