結果

問題 No.8018 簡易版ページランク
ユーザー fura
提出日時 2020-06-14 03:47:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 3,190 ms
コンパイル使用メモリ 197,832 KB
最終ジャッジ日時 2025-01-11 04:08:47
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         int n,m; scanf("%d%d",&n,&m);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:24:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |                 double c; scanf("%d%d%lf",&u,&v,&c);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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);
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	weighted_graph<double> G(n);
	rep(i,m){
		int u,v;
		double c; scanf("%d%d%lf",&u,&v,&c);
		add_directed_edge(G,u,v,c);
	}

	vector<double> curr(n,10),next(n);
	rep(t,100){
		fill(next.begin(),next.end(),0);
		rep(u,n){
			double sum=0;
			for(auto e:G[u]) sum+=e.wt;
			for(auto e:G[u]) next[e.to]+=(e.wt/sum)*curr[u];
		}
		copy(next.begin(),next.end(),curr.begin());
	}
	rep(u,n) printf("%.9f\n",curr[u]);

	return 0;
}
0