Submission #2089386
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int in() { int x; scanf("%d", &x); return x; }
template<typename T> void pv(T a, T b) { for (T i = a; i < b; i++) cout << *i << ' '; cout << endl; }
template<typename T, typename U> void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void chmax(T &x, U y) { if (x < y) x = y; }
vector<pair<int,int>> edges[200010];
bool visited[100010];
int calc(int s, int g, int c) {
// cout << s << ' ' << g << endl;
visited[s] = true;
if (s == g) return c;
REP(i,edges[s].size()) {
int to = edges[s][i].first;
int cost = edges[s][i].second;
if (!visited[to]) {
return calc(to,g,c+cost);
}
}
return -1;
}
int main() {
int N = in(), M = in();
REP(x,M) {
int l = in(), r = in(), d = in();
REP(i,100010) visited[i] = false;
int cost = calc(l,r,0);
if (cost != d && cost != -1) {
cout << "No" << endl;
return 0;
}
edges[l].push_back(make_pair(r, d));
edges[r].push_back(make_pair(l, d));
}
cout << "Yes" << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - People on a Line |
| User | jyane |
| Language | C++14 (GCC 5.4.1) |
| Score | 0 |
| Code Size | 1171 Byte |
| Status | WA |
| Exec Time | 2104 ms |
| Memory | 7424 KiB |
Compile Error
./Main.cpp: In function ‘int in()’:
./Main.cpp:7:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int in() { int x; scanf("%d", &x); return x; }
^
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 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 | TLE | 2104 ms | 7164 KiB |
| 02.txt | TLE | 2104 ms | 7292 KiB |
| 03.txt | TLE | 2104 ms | 7424 KiB |
| 04.txt | TLE | 2104 ms | 7424 KiB |
| 05.txt | AC | 1946 ms | 7296 KiB |
| 06.txt | WA | 922 ms | 6400 KiB |
| 07.txt | AC | 993 ms | 6400 KiB |
| 08.txt | WA | 1067 ms | 6528 KiB |
| 09.txt | WA | 542 ms | 5888 KiB |
| 10.txt | WA | 731 ms | 6144 KiB |
| 11.txt | AC | 1078 ms | 6528 KiB |
| 12.txt | AC | 1085 ms | 6528 KiB |
| 13.txt | WA | 1729 ms | 7040 KiB |
| 14.txt | WA | 1400 ms | 6912 KiB |
| 15.txt | AC | 1156 ms | 6528 KiB |
| 16.txt | AC | 588 ms | 5888 KiB |
| 17.txt | TLE | 2104 ms | 7424 KiB |
| 18.txt | WA | 1001 ms | 6400 KiB |
| 19.txt | WA | 572 ms | 5888 KiB |
| 20.txt | WA | 339 ms | 5632 KiB |
| 21.txt | TLE | 2104 ms | 7424 KiB |
| 22.txt | AC | 847 ms | 6272 KiB |
| 23.txt | TLE | 2104 ms | 7424 KiB |
| 24.txt | AC | 733 ms | 6144 KiB |
| 25.txt | WA | 310 ms | 5504 KiB |
| 26.txt | TLE | 2104 ms | 7424 KiB |
| 27.txt | WA | 994 ms | 6528 KiB |
| 28.txt | WA | 810 ms | 6272 KiB |
| 29.txt | WA | 661 ms | 6016 KiB |
| 30.txt | WA | 814 ms | 6272 KiB |
| 31.txt | WA | 818 ms | 6272 KiB |
| 32.txt | WA | 590 ms | 5888 KiB |
| 33.txt | TLE | 2104 ms | 7424 KiB |
| 34.txt | TLE | 2104 ms | 7424 KiB |
| 35.txt | AC | 856 ms | 6272 KiB |
| 36.txt | AC | 1277 ms | 6784 KiB |
| 37.txt | AC | 1034 ms | 6528 KiB |
| 38.txt | AC | 693 ms | 6016 KiB |
| 39.txt | AC | 532 ms | 5888 KiB |
| 40.txt | AC | 1117 ms | 6656 KiB |
| 41.txt | AC | 3 ms | 4992 KiB |
| 42.txt | AC | 601 ms | 5504 KiB |
| sample01.txt | AC | 3 ms | 4992 KiB |
| sample02.txt | AC | 3 ms | 4992 KiB |
| sample03.txt | AC | 3 ms | 4992 KiB |
| sample04.txt | AC | 3 ms | 4992 KiB |
| sample05.txt | AC | 3 ms | 4992 KiB |