Submission #3452089
Source Code Expand
#include<bits/stdc++.h> #define N 200010 using namespace std; struct edge{int ne,to,w;}e[N]; int x,y,w,n,m,es,head[N],vis[N],cal[N],ys=1,mx,mn,ans; inline int read(){ int x=0,sgn=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar())if(ch=='-')sgn=-1; for(;isdigit(ch);ch=getchar())x=x*10+(ch^48); return sgn*x; } inline void add(int x,int y,int w){ e[++es]=(edge){head[x],y,w}; head[x]=es; } inline void dfs(int x){ vis[x]=1;mx=max(mx,cal[x]),mn=min(mn,cal[x]); for(int i=head[x];i;i=e[i].ne){ int v=e[i].to; if(ys==0) return; if(vis[v]) {if(cal[v]!=cal[x]+e[i].w) {ys=0;return;}} else{ cal[v]=cal[x]+e[i].w; dfs(v); } } } int main(){ n=read(),m=read(); for(int i=1;i<=m;i++){ x=read(),y=read(),w=read(); if(x==y) continue; add(x,y,w),add(y,x,-w); } for(int i=1;i<=n;i++){ mx=-1e9,mn=1e9; if(!vis[i]) dfs(i); if(ys==0) {printf("No");return 0;} ans=max(ans,mx-mn); } printf("Yes"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - People on a Line |
User | luogu_bot1 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 977 Byte |
Status | RE |
Exec Time | 117 ms |
Memory | 3584 KB |
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 | RE | 110 ms | 3328 KB |
02.txt | RE | 110 ms | 3328 KB |
03.txt | RE | 111 ms | 3328 KB |
04.txt | RE | 110 ms | 3328 KB |
05.txt | RE | 110 ms | 3328 KB |
06.txt | RE | 110 ms | 3328 KB |
07.txt | RE | 110 ms | 3328 KB |
08.txt | RE | 110 ms | 3328 KB |
09.txt | RE | 110 ms | 3328 KB |
10.txt | RE | 110 ms | 3328 KB |
11.txt | RE | 110 ms | 3328 KB |
12.txt | RE | 110 ms | 3328 KB |
13.txt | RE | 109 ms | 3328 KB |
14.txt | RE | 110 ms | 3328 KB |
15.txt | RE | 108 ms | 3328 KB |
16.txt | RE | 110 ms | 3328 KB |
17.txt | RE | 110 ms | 3328 KB |
18.txt | RE | 109 ms | 3328 KB |
19.txt | RE | 111 ms | 3328 KB |
20.txt | RE | 111 ms | 3328 KB |
21.txt | RE | 109 ms | 3328 KB |
22.txt | RE | 110 ms | 3328 KB |
23.txt | RE | 110 ms | 3328 KB |
24.txt | RE | 110 ms | 3328 KB |
25.txt | RE | 111 ms | 3328 KB |
26.txt | RE | 117 ms | 3328 KB |
27.txt | RE | 111 ms | 3328 KB |
28.txt | RE | 110 ms | 3328 KB |
29.txt | RE | 111 ms | 3328 KB |
30.txt | RE | 110 ms | 3328 KB |
31.txt | RE | 111 ms | 3328 KB |
32.txt | RE | 111 ms | 3328 KB |
33.txt | RE | 110 ms | 3328 KB |
34.txt | RE | 109 ms | 3328 KB |
35.txt | RE | 111 ms | 3328 KB |
36.txt | RE | 109 ms | 3328 KB |
37.txt | RE | 110 ms | 3328 KB |
38.txt | RE | 110 ms | 3328 KB |
39.txt | RE | 110 ms | 3328 KB |
40.txt | RE | 109 ms | 3328 KB |
41.txt | AC | 2 ms | 2688 KB |
42.txt | AC | 10 ms | 3584 KB |
sample01.txt | AC | 2 ms | 2304 KB |
sample02.txt | AC | 2 ms | 2304 KB |
sample03.txt | AC | 2 ms | 2304 KB |
sample04.txt | AC | 2 ms | 2304 KB |
sample05.txt | AC | 2 ms | 2304 KB |