QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#221363#6845. TaxrealIyxiang#Compile Error//C++141.3kb2023-10-21 12:51:322023-10-21 12:51:33

Judging History

你现在查看的是最新测评结果

  • [2023-10-21 12:51:33]
  • 评测
  • [2023-10-21 12:51:32]
  • 提交

answer

#include <queue>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 50 + 5;
struct edge { int v, c; } e[N * N]; 
int n, m, u, v, c, res, ans[N], cnt[N], dep[N], w[N * N];  
vector <edge> G[N], H[N]; 
queue <int> Q; 

void add1 (int u, int v, int c) {
  G[u].push_back((edge){v, c}); 
  G[v].push_back((edge){u, c}); 
}
void add2 (int u, int v, int c) {
  cerr << u << ' ' << v << ' ' << c << '\n'; 
  H[u].push_back((edge){v, c}); 
}
void BFS (int s) {
  dep[s] = 0, Q.push(s);
  while (!Q.empty()) {
    int u = Q.front(); Q.pop(); 
    for (auto e : G[u]) 
      if(!dep[e.v] && e.v != s) dep[e.v] = dep[u] + 1, Q.push(e.v); 
  }
}
void dfs (int u) {
  ans[u] = min(ans[u], res); 
  for (auto e : H[u]) {
    ++cnt[e.c], res += cnt[e.c] * w[e.c]; 
    dfs(e.v); 
    res -= cnt[e.c] * w[e.c], --cnt[e.c]; 
  }
}

int main () {
  ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0); 
  cin >> n >> m;
  rep(i, 1, m) cin >> w[i]; 
  rep(i, 1, m) cin >> u >> v >> c, add1(u, v, c); 
  BFS(1); 
  // cerr << "ok\n"; 
  rep(i, 1, n) for (auto e : G[i]) 
    if(dep[i] + 1 == dep[e.v]) add2(i, e.v, e.c); 
  memset(ans, 0x7f, sizeof(ans)); 
  dfs(1); 
  rep(i, 2, n) cout << ans[i] << '\n'; 
  return 0; 
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:48:3: error: ‘memset’ was not declared in this scope
   48 |   memset(ans, 0x7f, sizeof(ans));
      |   ^~~~~~
answer.code:6:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    5 | #include <algorithm>
  +++ |+#include <cstring>
    6 | using namespace std;