Submission #3814100


Source Code Expand

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

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

map<int,vector<pair<int,ll>>> mp;

ll dfs(int v1, int v2, int p, ll c){
    if(v1 == v2){
        return c;
    }
    auto itr = mp[v1].begin();
    while(itr != mp[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";
    
    for(int i=0; i<m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        mp[a-1].push_back({b-1,c});
        mp[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 993 Byte
Status RE
Exec Time 2120 ms
Memory 270720 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 5
AC × 6
TLE × 9
RE × 32
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 TLE 2106 ms 43648 KB
02.txt TLE 2104 ms 7296 KB
03.txt TLE 2120 ms 267904 KB
04.txt TLE 2105 ms 20352 KB
05.txt RE 968 ms 270208 KB
06.txt RE 433 ms 267520 KB
07.txt RE 434 ms 270080 KB
08.txt RE 574 ms 269056 KB
09.txt RE 500 ms 266112 KB
10.txt RE 411 ms 269568 KB
11.txt RE 355 ms 268544 KB
12.txt RE 344 ms 267520 KB
13.txt RE 983 ms 268544 KB
14.txt RE 662 ms 269056 KB
15.txt RE 377 ms 267904 KB
16.txt RE 404 ms 267904 KB
17.txt TLE 2106 ms 45952 KB
18.txt RE 475 ms 267008 KB
19.txt RE 584 ms 266368 KB
20.txt RE 347 ms 267392 KB
21.txt RE 1939 ms 269312 KB
22.txt RE 698 ms 269184 KB
23.txt TLE 2109 ms 86016 KB
24.txt RE 416 ms 267648 KB
25.txt RE 330 ms 265344 KB
26.txt TLE 2107 ms 55168 KB
27.txt RE 378 ms 270080 KB
28.txt RE 411 ms 267008 KB
29.txt RE 360 ms 267648 KB
30.txt RE 326 ms 266240 KB
31.txt RE 398 ms 270720 KB
32.txt RE 349 ms 267136 KB
33.txt TLE 2109 ms 80768 KB
34.txt TLE 2110 ms 98176 KB
35.txt RE 345 ms 267392 KB
36.txt RE 820 ms 269056 KB
37.txt RE 361 ms 269440 KB
38.txt RE 388 ms 267264 KB
39.txt RE 339 ms 266496 KB
40.txt RE 460 ms 269440 KB
41.txt AC 1 ms 256 KB
42.txt RE 611 ms 262400 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