Submission #7067589
Source Code Expand
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(),a.end() #define F first #define S second #define pb push_back #define ll long long #define ld long double #define mkp make_pair #define sz(x) (int)x.size() #define pi pair<long long, long long> #define endl '\n' #define _ << ' ' #define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x))) #define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset; //find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x const ll mod = (ll)1e9+7; const ll INF = (ll)3e9+1; bool ok=0; ll n, m, a, b, c; ll v[100001]; vector< pair<ll, ll> > adj[100001]; void dfs(ll cur) { for(auto nxt : adj[cur]) { if(ok) return; if(v[nxt.F]==INF) { v[nxt.F] = v[cur] + nxt.S; dfs(nxt.F); } else if(v[nxt.F]-v[cur]!=nxt.S) { cout << "No"; ok = 1; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE //freopen("D.txt", "r", stdin); #endif cin >> n >> m; for(int i=1; i<=n; i++) v[i] = INF; for(int i=0; i<m; i++) { cin >> a >> b >> c; adj[a].pb({b, c}); adj[b].pb({a, -c}); } for(int i=1; i<=n; i++) { if(v[i]==INF) { v[i] = 0; dfs(i); } } if(!ok) cout << "Yes"; }
Submission Info
Submission Time | |
---|---|
Task | D - People on a Line |
User | animefan6588 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1742 Byte |
Status | AC |
Exec Time | 110 ms |
Memory | 16512 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | AC | 80 ms | 12784 KB |
02.txt | AC | 106 ms | 14064 KB |
03.txt | AC | 98 ms | 13696 KB |
04.txt | AC | 110 ms | 16512 KB |
05.txt | AC | 86 ms | 12288 KB |
06.txt | AC | 83 ms | 12032 KB |
07.txt | AC | 87 ms | 12032 KB |
08.txt | AC | 74 ms | 11520 KB |
09.txt | AC | 63 ms | 10880 KB |
10.txt | AC | 61 ms | 10624 KB |
11.txt | AC | 56 ms | 10624 KB |
12.txt | AC | 67 ms | 10752 KB |
13.txt | AC | 90 ms | 12288 KB |
14.txt | AC | 78 ms | 11008 KB |
15.txt | AC | 67 ms | 10880 KB |
16.txt | AC | 70 ms | 11264 KB |
17.txt | AC | 100 ms | 15232 KB |
18.txt | AC | 86 ms | 12160 KB |
19.txt | AC | 69 ms | 11520 KB |
20.txt | AC | 71 ms | 11520 KB |
21.txt | AC | 88 ms | 13184 KB |
22.txt | AC | 64 ms | 11136 KB |
23.txt | AC | 90 ms | 13568 KB |
24.txt | AC | 65 ms | 11136 KB |
25.txt | AC | 102 ms | 15104 KB |
26.txt | AC | 110 ms | 15232 KB |
27.txt | AC | 53 ms | 12160 KB |
28.txt | AC | 75 ms | 11904 KB |
29.txt | AC | 63 ms | 13184 KB |
30.txt | AC | 68 ms | 11520 KB |
31.txt | AC | 56 ms | 11392 KB |
32.txt | AC | 68 ms | 11648 KB |
33.txt | AC | 98 ms | 15104 KB |
34.txt | AC | 96 ms | 13952 KB |
35.txt | AC | 53 ms | 11776 KB |
36.txt | AC | 65 ms | 10880 KB |
37.txt | AC | 57 ms | 12416 KB |
38.txt | AC | 66 ms | 11392 KB |
39.txt | AC | 46 ms | 9088 KB |
40.txt | AC | 61 ms | 11008 KB |
41.txt | AC | 3 ms | 3328 KB |
42.txt | AC | 27 ms | 7036 KB |
sample01.txt | AC | 2 ms | 2560 KB |
sample02.txt | AC | 2 ms | 2560 KB |
sample03.txt | AC | 2 ms | 2560 KB |
sample04.txt | AC | 2 ms | 2560 KB |
sample05.txt | AC | 2 ms | 2560 KB |