답안 #41705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41705 2018-02-21T01:58:24 Z wzy 페리들 (NOI13_ferries) C++11
40 / 40
585 ms 32768 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
int fx[100005] , n , m;
vector<int> adj[100005] ;
vector<int>  radj[100005];
vector<int> p[100005];

bool cmp(int i , int j){
	if(fx[i] == fx[j]) return i;
	else{
		return fx[i] > fx[j];
	}
}


int32_t main(){
	scanf("%d%d" , &n , &m);
	vector<pii> edges;
	for(int i = 0 ; i < m ; i++){
		int x, y,z;
		cin>>x>>y>>z;
		x--, y--;
		p[x].pb(z);
		adj[x].pb(y);
		edges.pb(pii(x,y));
	}
	for(int i = 0 ; i < n;i++) sort(p[i].begin() , p[i].end()), fx[i] = 1000000009;
	for(int i =0;i<m;i++){
		radj[edges[i].S].pb(edges[i].F);
	}
	priority_queue<pii , vector<pii> , greater<pii> > pq;
	fx[n-1] = 0;
	pq.push(pii(0 , n-1));
	while(!pq.empty()){
		pii u = pq.top();
		pq.pop();
		if(fx[u.S] != u.F) continue;
		for(int j = 0 ; j < radj[u.S].size(); j++){
			pii v =pii(0 ,  radj[u.S][j]);
			if(p[v.S].size()){
				v.F = p[v.S].back();
				p[v.S].pop_back();
			}
			else continue;
			if(fx[v.S] > v.F + u.F){
				fx[v.S] = v.F + u.F;
				pq.push(pii(fx[v.S] , v.S));
			}
		}
	}
	printf("%d\n" , fx[0]);
}

Compilation message

ferries.cpp: In function 'int32_t main()':
ferries.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0 ; j < radj[u.S].size(); j++){
                     ^
ferries.cpp:21:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &m);
                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7288 KB Output is correct
2 Correct 13 ms 7524 KB Output is correct
3 Correct 36 ms 9408 KB Output is correct
4 Correct 304 ms 25156 KB Output is correct
5 Correct 276 ms 26280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 26280 KB Output is correct
2 Correct 8 ms 26280 KB Output is correct
3 Correct 30 ms 26280 KB Output is correct
4 Correct 134 ms 26280 KB Output is correct
5 Correct 217 ms 26280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 26280 KB Output is correct
2 Correct 50 ms 26280 KB Output is correct
3 Correct 524 ms 30108 KB Output is correct
4 Correct 567 ms 32768 KB Output is correct
5 Correct 512 ms 32768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 523 ms 32768 KB Output is correct
2 Correct 551 ms 32768 KB Output is correct
3 Correct 559 ms 32768 KB Output is correct
4 Correct 585 ms 32768 KB Output is correct
5 Correct 548 ms 32768 KB Output is correct