結果
| 問題 |
No.30 たこやき工場
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-19 23:27:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 973 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 53,040 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-02 19:22:42 |
| 合計ジャッジ時間 | 2,445 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 3 RE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d %d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | scanf("%d %lld %d", &p, &q, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
typedef long long ll;
struct Edge{
int to;
ll cost;
};
int N, M;
std::vector<Edge> G[101], rG[101];
std::vector<int> order;
bool used[101];
ll d[101];
void dfs(int u){
used[u] = true;
for(auto e : G[u]){
if(!used[e.to]){
dfs(e.to);
}
}
order.push_back(u);
}
int main(){
scanf("%d %d", &N, &M);
for(int i=0;i<M;i++){
int p, r;
ll q;
scanf("%d %lld %d", &p, &q, &r);
G[r].push_back({p, q});
rG[p].push_back({r, q});
}
dfs(N);
d[N] = 1ll;
for(int i=N-2;i>=0;i--){
for(auto e : rG[order[i]]){
d[order[i]] += d[e.to] * e.cost;
}
}
for(int i=1;i<N;i++){
if(G[i].empty()){
printf("%lld\n", d[i]);
}else{
puts("0");
}
}
}
tottoripaper