Submission #3813879


Source Code Expand

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

typedef long long ll;
ll const inf = 1e18;

vector<vector<pair<int,int>>> vec;

ll dfs(int v1, int v2, int p, ll c){
    if(v1 == v2){
        return c;
    }
    auto itr = vec.at(v1).begin();
    while(itr != vec.at(v1).end()){
        if((*itr).first == p){
            itr++;
            continue;
        }
        ll d = dfs((*itr).first, v2, v1, c + (*itr).second);
        if(d != inf){
            return d;
        }
        itr++;
    }
    return inf;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    string ans = "Yes";
    
    vec.resize(n);
    for(int i=0; i<m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        vec.at(a-1).push_back({b-1,c});
        vec.at(b-1).push_back({a-1,-c});
        ll d = dfs(a-1, b-1, -1, 0);
        if(d != inf && d != c){
            ans = "No";
        }
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task D - People on a Line
User Almond
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1020 Byte
Status RE
Exec Time 2111 ms
Memory 267008 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 5
AC × 6
TLE × 2
RE × 39
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 1860 ms 264832 KB
02.txt TLE 2110 ms 116480 KB
03.txt RE 472 ms 266752 KB
04.txt TLE 2111 ms 134912 KB
05.txt RE 316 ms 266880 KB
06.txt RE 258 ms 266112 KB
07.txt RE 259 ms 266880 KB
08.txt RE 278 ms 266624 KB
09.txt RE 276 ms 265728 KB
10.txt RE 258 ms 266752 KB
11.txt RE 257 ms 266496 KB
12.txt RE 252 ms 266112 KB
13.txt RE 303 ms 266496 KB
14.txt RE 285 ms 266624 KB
15.txt RE 257 ms 266240 KB
16.txt RE 262 ms 266240 KB
17.txt RE 796 ms 266880 KB
18.txt RE 266 ms 265984 KB
19.txt RE 274 ms 265856 KB
20.txt RE 250 ms 266112 KB
21.txt RE 380 ms 266624 KB
22.txt RE 290 ms 266624 KB
23.txt RE 781 ms 266752 KB
24.txt RE 261 ms 266240 KB
25.txt RE 243 ms 265600 KB
26.txt RE 860 ms 266880 KB
27.txt RE 253 ms 266880 KB
28.txt RE 255 ms 265984 KB
29.txt RE 250 ms 266240 KB
30.txt RE 245 ms 265856 KB
31.txt RE 256 ms 267008 KB
32.txt RE 246 ms 265984 KB
33.txt RE 704 ms 266752 KB
34.txt RE 603 ms 266880 KB
35.txt RE 249 ms 266112 KB
36.txt RE 295 ms 266624 KB
37.txt RE 252 ms 266752 KB
38.txt RE 253 ms 266112 KB
39.txt RE 248 ms 265856 KB
40.txt RE 259 ms 266752 KB
41.txt AC 3 ms 2560 KB
42.txt RE 317 ms 264704 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB
sample04.txt AC 1 ms 256 KB
sample05.txt AC 1 ms 256 KB