Submission #44548

# Submission time Handle Problem Language Result Execution time Memory
44548 2018-04-03T04:52:49 Z vatsalsharma376 Sightseeing (NOI14_sightseeing) C++14
25 / 25
3107 ms 166872 KB
/*
     Contest  :
     Task    :
*/
 #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 #define getcx getchar_unlocked
#define putcx putchar_unlocked
#define pb  push_back
#define mp  make_pair
#define ll  long long
#define F   first
#define S   second
#define itr ::iterator 
 
typedef pair<int,int> pii;
 
const int MAX=6e5+99;
 
vector<pii> vec[MAX];
 
int V,E,Q,X,Y,Z,res[MAX];
 int IN () {                                       // REMEMBER TO CHANGE DATATYPE
    bool minus = false;                                     
    int result = 0;
    char ch;
    ch = getcx();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getcx();
    }
    if (ch == '-') minus = true; else result = ch-'0';
    while (true) {
        ch = getcx();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
template<class ty>void oup(ty x) {
        char s[20];
        short i=0;
        do{
            s[i++]=x%10+'0';
            x/=10;
        }while(x);
        --i;
        while(i>-1)putcx(s[i--]);
}
void dijkstra()
{
	int tem;
	pii cur;
	priority_queue<pii> pq;
	pq.push(mp(MAX,1));
	res[1]=MAX;
	while(! pq.empty())
	{
		cur=pq.top();
		pq.pop();
		if(cur.first < res[cur.second])
		continue;
		for(auto A:vec[cur.second])
		{
		    tem=min(cur.first,A.second);
			if(tem>res[A.first])
			{
				res[A.first]=tem;
				pq.push(mp(res[A.first],A.first));
			}
		}
	}
	return ;
}
 
signed main()
{
	//ios_base::sync_with_stdio(false);
	/*cin.tie(0);
	cout.tie(0);*/
	
	//cin>>V>>E>>Q;
	V=IN(); E=IN(); Q=IN();
	while(E--)
	{
		X=IN(); Y=IN(); Z=IN();
		vec[X].pb(mp(Y,Z));
		vec[Y].pb(mp(X,Z));
	}
	dijkstra();
	while(Q--)
	{
		X=IN();
		oup(res[X]);
		puts("");
	}
    return 0;
}

Compilation message

sightseeing.cpp:5:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
  #pragma comment(linker, "/stack:200000000")
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14328 KB Output is correct
2 Correct 14 ms 14436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14640 KB Output is correct
2 Correct 14 ms 14640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 16608 KB Output is correct
2 Correct 41 ms 16608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2345 ms 108372 KB Output is correct
2 Correct 3107 ms 166872 KB Output is correct