結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-07 01:39:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 1,244 bytes |
| コンパイル時間 | 3,039 ms |
| コンパイル使用メモリ | 206,064 KB |
| 最終ジャッジ日時 | 2025-01-12 15:35:46 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 31 |
| other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | int n,m; scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:40:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | int u,v,c; scanf("%d%d%d",&u,&v,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
template<class T> struct edge{
int to;
T wt;
edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;
template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
G[u].emplace_back(v,wt);
}
template<class T>
vector<int> topological_order(const weighted_graph<T>& D){
int n=D.size();
vector<int> deg(n);
rep(u,n) for(const auto& e:D[u]) deg[e.to]++;
vector<int> res;
queue<int> Q;
rep(u,n) if(deg[u]==0) Q.emplace(u);
while(!Q.empty()){
int u=Q.front(); Q.pop();
res.emplace_back(u);
for(const auto& e:D[u]) if(--deg[e.to]==0) Q.emplace(e.to);
}
return res;
}
int main(){
int n,m; scanf("%d%d",&n,&m);
weighted_graph<int> G(n);
rep(i,m){
int u,v,c; scanf("%d%d%d",&u,&v,&c);
add_directed_edge(G,u,v,c);
}
auto p=topological_order(G);
vector<int> dp(n);
for(int u:p){
for(auto e:G[u]) dp[e.to]=max(dp[e.to],dp[u]+e.wt);
}
vector<bool> ok(n);
ok[n-1]=true;
rep(i,n){
int u=p[n-1-i];
for(auto e:G[u]) if(ok[e.to] && dp[e.to]==dp[u]+e.wt) ok[u]=true;
}
printf("%d %ld/%d\n",dp[n-1],count(ok.begin(),ok.end(),false),n);
return 0;
}