Submission #3453217
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N=1e5*2+10; inline int read() { char ch=getchar(); int x=0,f=1; while (ch>'9' || ch<'0') { if (ch=='-') f=-1; ch=getchar(); } while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } int i,j,k,t,m,n,mind,maxd; int dis[N<<1]; bool vis[N<<1]; struct EDGE { int nex,to,w; } edge[N<<1]; int head[N<<1],cnt,ans; inline void add(int x,int y,int z) { edge[++cnt].to=y; edge[cnt].nex=head[x]; head[x]=cnt; edge[cnt].w=z; } int fail=0; inline bool dfs(int u) { vis[u]=1; for (int i=head[u];i;i=edge[i].nex) { int v=edge[i].to,w=edge[i].w; if (vis[v]) { if (dis[u]+w!=dis[v]) return false; } else { dis[v]=dis[u]+w; maxd=max(maxd,dis[v]); mind=min(mind,dis[v]); if (!dfs(v)) return false; } } return true; } int main() { n=read();m=read(); for (int i=1;i<=m;i++) { int x=read(),y=read(),z=read(); add(x,y,z); add(y,x,-z); } for (int i=1;i<=n;i++) { if (!vis[i]) { dis[i]=0; maxd=0; mind=0; if (!dfs(i)) { fail=1; break; } ans=max(ans,maxd-mind); } } if (fail) { printf("impossible"); return 0; } else printf("%d\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - People on a Line |
User | luogu_bot4 |
Language | C++ (GCC 5.4.1) |
Score | 0 |
Code Size | 1299 Byte |
Status | WA |
Exec Time | 38 ms |
Memory | 8320 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 | WA | 25 ms | 7296 KB |
02.txt | WA | 33 ms | 7680 KB |
03.txt | WA | 26 ms | 7296 KB |
04.txt | WA | 38 ms | 8320 KB |
05.txt | WA | 24 ms | 7296 KB |
06.txt | WA | 26 ms | 7808 KB |
07.txt | WA | 23 ms | 7296 KB |
08.txt | WA | 25 ms | 7680 KB |
09.txt | WA | 23 ms | 7680 KB |
10.txt | WA | 22 ms | 7680 KB |
11.txt | WA | 21 ms | 7552 KB |
12.txt | WA | 20 ms | 7296 KB |
13.txt | WA | 29 ms | 7424 KB |
14.txt | WA | 23 ms | 7552 KB |
15.txt | WA | 23 ms | 7296 KB |
16.txt | WA | 22 ms | 7552 KB |
17.txt | WA | 32 ms | 8192 KB |
18.txt | WA | 30 ms | 7296 KB |
19.txt | WA | 25 ms | 7808 KB |
20.txt | WA | 25 ms | 7552 KB |
21.txt | WA | 28 ms | 7808 KB |
22.txt | WA | 20 ms | 7552 KB |
23.txt | WA | 28 ms | 7680 KB |
24.txt | WA | 19 ms | 7424 KB |
25.txt | WA | 34 ms | 8192 KB |
26.txt | WA | 32 ms | 8192 KB |
27.txt | WA | 21 ms | 6400 KB |
28.txt | WA | 25 ms | 7680 KB |
29.txt | WA | 22 ms | 6912 KB |
30.txt | WA | 24 ms | 7808 KB |
31.txt | WA | 22 ms | 6272 KB |
32.txt | WA | 24 ms | 7936 KB |
33.txt | WA | 27 ms | 7680 KB |
34.txt | WA | 28 ms | 8192 KB |
35.txt | WA | 21 ms | 6272 KB |
36.txt | WA | 23 ms | 7680 KB |
37.txt | WA | 19 ms | 6528 KB |
38.txt | WA | 21 ms | 7808 KB |
39.txt | WA | 19 ms | 6272 KB |
40.txt | WA | 22 ms | 7680 KB |
41.txt | WA | 2 ms | 2304 KB |
42.txt | WA | 10 ms | 5376 KB |
sample01.txt | WA | 1 ms | 2304 KB |
sample02.txt | WA | 1 ms | 2304 KB |
sample03.txt | WA | 1 ms | 2304 KB |
sample04.txt | WA | 1 ms | 2304 KB |
sample05.txt | WA | 1 ms | 2304 KB |