记录详情

Runtime Error

/in/foo.cc: In function 'int read()':
/in/foo.cc:6:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
                       ~~~~~~~^~~~~~~
# 状态 耗时 内存占用
#1 Accepted 41ms 6.938 MiB
#2 Accepted 80ms 12.266 MiB
#3 Accepted 155ms 23.477 MiB
#4 Accepted 147ms 23.414 MiB
#5 Accepted 153ms 23.434 MiB
#6 Runtime Error 116ms 25.238 MiB

代码

#include <bits/stdc++.h>
#define N 500020
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}

int to[N], nxt[N], head[N], cnt;
void insert(int x, int y) {
  to[++ cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}

// tarjan
int dfn[N], low[N], que[N], blo[N], qnt, bnt, tot, sz[N];
void tarjan(int x) {
  dfn[x] = low[x] = ++ tot;
  que[++ qnt] = x;
  for (int i = head[x]; i; i = nxt[i])
    if (!dfn[to[i]]) tarjan(to[i]), low[x] = min(low[x], low[to[i]]);
    else if (!blo[to[i]]) low[x] = min(low[x], dfn[to[i]]);
  if (dfn[x] == low[x] && ++ bnt)
    while (que[qnt + 1] != x)
      blo[que[qnt --]] = bnt, sz[bnt] ++;
}

int a[N], ed[N];

int to2[N], nxt2[N], head2[N], cnt2;
void insert2(int x, int y) {
  // printf("%d -> %d\n", x, y);
  to2[++ cnt2] = y;
  nxt2[cnt2] = head2[x];
  head2[x] = cnt2;
}

int e1[N], e2[N];
int ed2[N], val[N], f[N], g[N];

int main() {
  int n = read(), m = read();
  for (int i = 1; i <= m; ++ i) {
    e1[i] = read();
    e2[i] = read();
    if (e1[i] != e2[i]) {
      insert(e1[i], e2[i]);
    }
  }
  for (int i = 1; i <= n; ++ i) {
    a[i] = read();
  }
  int S = read(), P = read();
  for (int i = 1; i <= P; ++ i) {
    ed[read()] = 1;
  }

  for (int i = 1; i <= n; ++ i) {
    if (!dfn[i]) tarjan(i);
  }

  for (int i = 1; i <= m; ++ i) {
    int b1 = blo[e1[i]];
    int b2 = blo[e2[i]];
    if (b1 != b2) {
      insert2(b1, b2);
    }
  }

  for (int i = 1; i <= n; ++ i) {
    ed2[blo[i]] |= ed[i];
    val[blo[i]] += a[i];
  }

  int l = 0, r = 0, ans = 0;
  que[++ r] = blo[S];
  f[blo[S]] = val[blo[S]];
  while (l < r) {
    int x = que[++ l];
    if (ed2[x]) {
      ans = max(ans, f[x]);
    }
    for (int i = head2[x]; i; i = nxt2[i]) {
      f[to2[i]] = max(f[to2[i]], f[x] + val[to2[i]]);
      que[++ r] = to2[i];
    }
  }

  printf("%d\n", ans);
}

信息

递交者
类型
递交
题目
P1006 hitwh 2019 新生赛 G LFhase 与他的学术文章
语言
C++
递交时间
2020-12-17 11:57:34
评测时间
2020-12-17 12:06:12
评测机
分数
80
总耗时
694ms
峰值内存
25.238 MiB