#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
const int maxi= 2 * ( 1e6 + 10 ) ;
priority_queue < pair< long long ,int >> pq[ maxi] ;
vector < int > g[ maxi] ,ds[ maxi] ;
set < long long > st[ maxi] ;
vector < pair< int ,int >> mp[ maxi] ;
map < pair< int ,int > , int > c,ob;
long long ans[ maxi] ;
int gr[ maxi] ;
pair< long long , pair< int ,int >> v[ maxi] ;
int x,y,n,m,q;
long long z;
long long b[ maxi] ,cnt[ maxi] ;
void spoj( int x, int y,int z)
{
if ( x! = y)
{
if ( ds[ x] .size ( ) >= ds[ y] .size ( ) )
swap( x,y) ;
for ( int i= 0 ; i< ds[ x] .size ( ) ; i++ )
for ( int j= 0 ; j< g[ ds[ x] [ i] ] .size ( ) ; j++ )
{
int u= 0 ;
u= g[ ds[ x] [ i] ] [ j] ;
if ( gr[ u] == y && c[ { ds[ x] [ i] ,u} ] )
{
int o1= 0 ;
o1 = c[ { ds[ x] [ i] ,u} ] ;
for ( int w= 0 ; w< mp[ o1] .size ( ) ; w++ )
pq[ y] .push ( mp[ o1] [ w] ) ;
}
}
for ( int i= 0 ; i< ds[ x] .size ( ) ; i++ )
{
ds[ y] .push_back ( ds[ x] [ i] ) ;
st[ y] .insert ( b[ ds[ x] [ i] ] ) ;
gr[ ds[ x] [ i] ] = y;
}
st[ x] .clear ( ) ;
ds[ x] .clear ( ) ;
while ( ! pq[ x] .empty ( ) )
{
int p= 0 ;
int p1= 0 ;
p= pq[ x] .top ( ) .first ;
p1= pq[ x] .top ( ) .second ;
pq[ y] .push ( { p,p1} ) ;
pq[ x] .pop ( ) ;
}
while ( ! pq[ y] .empty ( ) && abs ( pq[ y] .top ( ) .first ) <= st[ y] .size ( ) )
{
ans[ pq[ y] .top ( ) .second ] = z;
pq[ y] .pop ( ) ;
}
}
}
int main( )
{
scanf ( "%d%d%d" ,& n,& m,& q) ;
for ( int i= 1 ; i<= n; i++ )
scanf ( "%lld" ,& b[ i] ) ;
for ( int i= 1 ; i<= n; i++ )
{
ds[ i] .push_back ( i) ;
st[ i] .insert ( b[ i] ) ;
gr[ i] = i;
}
int p= 0 ;
for ( int i= 0 ; i< m; i++ )
{
scanf ( "%d%d%d" ,& x,& y,& z) ;
if ( ! ob[ { x,y} ] )
{
p++ ;
ob[ { x,y} ] = 1 ;
ob[ { y,x} ] = 1 ;
v[ p- 1 ] = { z,{ x,y} } ;
g[ x] .push_back ( y) ;
g[ y] .push_back ( x) ;
}
}
sort( v,v+ p) ;
for ( int i= 1 ; i<= q; i++ )
ans[ i] = - 1 ;
int o= 0 ;
for ( int i= 1 ; i<= q; i++ )
{
scanf ( "%d%d%lld" ,& x,& y,& z) ;
if ( x== y)
{
if ( z<= 1 ) {
ans[ i] = 0 ;
cnt[ i] = 1 ;
}
else
pq[ x] .push ( { - z,i} ) ;
} else
{
if ( c[ { x,y} ] == 0 ) {
o++ ;
c[ { x,y} ] = o;
}
mp[ c[ { x,y} ] ] .push_back ( { - z,i} ) ;
if ( c[ { y,x} ] == 0 ) {
o++ ;
c[ { y,x} ] = o;
}
mp[ c[ { y,x} ] ] .push_back ( { - z,i} ) ;
}
}
for ( int i= 0 ; i< p; i++ )
spoj( gr[ v[ i] .second .first ] ,gr[ v[ i] .second .second ] ,v[ i] .first ) ;
for ( int i= 1 ; i<= q; i++ )
printf ( "%lld\n " ,ans[ i] ) ;
return 0 ;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c2V0PgojaW5jbHVkZTxxdWV1ZT4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxjbWF0aD4KI2luY2x1ZGU8bWFwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBtYXhpPTIqKDFlNisxMCk7Cgpwcmlvcml0eV9xdWV1ZSA8cGFpcjxsb25nIGxvbmcgLGludD4+IHBxW21heGldOwp2ZWN0b3IgPGludD4gZ1ttYXhpXSxkc1ttYXhpXTsKc2V0IDxsb25nIGxvbmc+IHN0W21heGldOwp2ZWN0b3IgPHBhaXI8aW50LGludD4+IG1wW21heGldOwptYXAgPHBhaXI8aW50LGludD4sIGludD4gYyxvYjsKbG9uZyBsb25nICBhbnNbbWF4aV07CmludCBnclttYXhpXTsKcGFpcjxsb25nIGxvbmcgLCBwYWlyPGludCxpbnQ+PiB2W21heGldOwppbnQgeCx5LG4sbSxxOwpsb25nIGxvbmcgejsKbG9uZyBsb25nIGJbbWF4aV0sY250W21heGldOwoKCnZvaWQgc3BvaihpbnQgeCwgaW50IHksaW50IHopCnsKCiAgIGlmICh4IT15KQogICB7CiAgICBpZiAoZHNbeF0uc2l6ZSgpPj1kc1t5XS5zaXplKCkpCiAgICAgc3dhcCh4LHkpOwoKICBmb3IgKGludCBpPTA7aTxkc1t4XS5zaXplKCk7aSsrKQogICAgZm9yIChpbnQgaj0wO2o8Z1tkc1t4XVtpXV0uc2l6ZSgpO2orKykKICAgICAgIHsKICAgICAgICAgICBpbnQgdT0wOwogICAgICAgICAgIHU9Z1tkc1t4XVtpXV1bal07CiAgICAgICAgICAgaWYgKGdyW3VdPT15ICYmIGNbe2RzW3hdW2ldLHV9XSkKICAgICAgICB7CiAgICAgICAgICAgIGludCBvMT0wOwogICAgICAgICAgICBvMSA9Y1t7ZHNbeF1baV0sdX1dOwogICAgICAgICAgICAgZm9yIChpbnQgdz0wO3c8bXBbbzFdLnNpemUoKTt3KyspCiAgICAgICAgICAgICBwcVt5XS5wdXNoKG1wW28xXVt3XSk7CiAgICAgICAgfQoKICAgICAgIH0KICAgICAgICAgICAgZm9yIChpbnQgaT0wO2k8ZHNbeF0uc2l6ZSgpO2krKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICBkc1t5XS5wdXNoX2JhY2soZHNbeF1baV0pOwogICAgICAgICAgICAgICBzdFt5XS5pbnNlcnQoYltkc1t4XVtpXV0pOwogICAgICAgICAgICAgICBncltkc1t4XVtpXV09eTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgc3RbeF0uY2xlYXIoKTsKICAgICAgICAgICAgZHNbeF0uY2xlYXIoKTsKCiAgICAgICAgICAgIHdoaWxlKCFwcVt4XS5lbXB0eSgpKQogICAgICAgICAgICAgewogICAgICAgICAgICAgICAgIGludCBwPTA7CiAgICAgICAgICAgICAgICAgaW50IHAxPTA7CiAgICAgICAgICAgICAgICAgIHA9cHFbeF0udG9wKCkuZmlyc3Q7CiAgICAgICAgICAgICAgICAgIHAxPXBxW3hdLnRvcCgpLnNlY29uZDsKICAgICAgICAgICAgICAgICBwcVt5XS5wdXNoKHtwLHAxfSk7CiAgICAgICAgICAgICAgICAgcHFbeF0ucG9wKCk7CiAgICAgICAgICAgICB9CgogICAgICAgICAgICAgd2hpbGUoIXBxW3ldLmVtcHR5KCkgJiYgYWJzKHBxW3ldLnRvcCgpLmZpcnN0KTw9c3RbeV0uc2l6ZSgpKQogICAgICAgICAgICAgewogICAgICAgICAgICAgICAgIGFuc1twcVt5XS50b3AoKS5zZWNvbmRdPXo7CiAgICAgICAgICAgICAgICAgcHFbeV0ucG9wKCk7CiAgICAgICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCkKewogICAgc2NhbmYoIiVkJWQlZCIsJm4sJm0sJnEpOwoKICAgIGZvciAoaW50IGk9MTtpPD1uO2krKykKICAgICBzY2FuZigiJWxsZCIsJmJbaV0pOwoKICAgIGZvciAoaW50IGk9MTtpPD1uO2krKykKICAgIHsKICAgICAgICBkc1tpXS5wdXNoX2JhY2soaSk7CiAgICAgICAgc3RbaV0uaW5zZXJ0KGJbaV0pOwogICAgICAgIGdyW2ldPWk7CiAgICB9CiBpbnQgcD0wOwogICAgZm9yIChpbnQgaT0wO2k8bTtpKyspCiAgICB7CiAgICAgICAgIHNjYW5mKCIlZCVkJWQiLCZ4LCZ5LCZ6KTsKICAgICAgICAgaWYgKCFvYlt7eCx5fV0pCiAgICAgICAgICAgIHsKCiAgICAgICAgICAgICAgICBwKys7CgogICAgICAgICAgICBvYlt7eCx5fV09MTsKICAgICAgICAgICAgb2Jbe3kseH1dPTE7CiAgICAgICAgIHZbcC0xXT17eix7eCx5fX07CiAgICAgICAgIGdbeF0ucHVzaF9iYWNrKHkpOwogICAgICAgICBnW3ldLnB1c2hfYmFjayh4KTsKICAgICAgICAgICAgfQogICAgfQoKCiAgICBzb3J0KHYsditwKTsKCmZvciAoaW50IGk9MTtpPD1xO2krKykKICAgICAgICAgICAgYW5zW2ldPS0xOwogaW50IG89MDsKICAgIGZvciAoaW50IGk9MTtpPD1xO2krKykKICAgIHsKICAgICAgICBzY2FuZigiJWQlZCVsbGQiLCZ4LCZ5LCZ6KTsKICAgICAgICBpZiAoeD09eSkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh6PD0xKSAgewogICAgICAgICAgICAgICAgYW5zW2ldPTA7CiAgICAgICAgICAgICAgICBjbnRbaV09MTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHBxW3hdLnB1c2goey16LGl9KTsKICAgICAgICB9IGVsc2UKICAgICAgICB7CiAgICAgICAgaWYgKGNbe3gseX1dPT0wKSAgewogICAgICAgICAgICBvKys7CiAgICAgICAgY1t7eCx5fV09bzsKICAgICAgICB9CiAgICAgICAgbXBbY1t7eCx5fV1dLnB1c2hfYmFjayh7LXosaX0pOwogICAgICAgIGlmIChjW3t5LHh9XT09MCkgIHsKICAgICAgICBvKys7CiAgICAgICAgY1t7eSx4fV09bzsKICAgICAgICB9CiAgICAgICAgbXBbY1t7eSx4fV1dLnB1c2hfYmFjayh7LXosaX0pOwogICAgIH0KICAgIH0KCiAgICBmb3IgKGludCBpPTA7aTxwO2krKykKICAgICAgICBzcG9qKGdyW3ZbaV0uc2Vjb25kLmZpcnN0XSxnclt2W2ldLnNlY29uZC5zZWNvbmRdLHZbaV0uZmlyc3QpOwoKICBmb3IgKGludCBpPTE7aTw9cTtpKyspCiAgICBwcmludGYoIiVsbGRcbiIsYW5zW2ldKTsKCiAgICByZXR1cm4gMDsKfQo=
compilation info
prog.cpp:14:36: error: a space is required between consecutive right angle brackets (use '> >')
priority_queue <pair<long long ,int>> pq[maxi];
^~
> >
prog.cpp:17:21: error: a space is required between consecutive right angle brackets (use '> >')
vector <pair<int,int>> mp[maxi];
^~
> >
prog.cpp:21:30: error: a space is required between consecutive right angle brackets (use '> >')
pair<long long , pair<int,int>> v[maxi];
^~
> >
prog.cpp:40:30: error: expected expression
if (gr[u]==y && c[{ds[x][i],u}])
^
prog.cpp:40:30: error: expected ']'
prog.cpp:40:29: note: to match this '['
if (gr[u]==y && c[{ds[x][i],u}])
^
prog.cpp:43:19: error: expected expression
o1 =c[{ds[x][i],u}];
^
prog.cpp:43:19: error: expected ']'
prog.cpp:43:18: note: to match this '['
o1 =c[{ds[x][i],u}];
^
prog.cpp:65:29: error: expected expression
pq[y].push({p,p1});
^
prog.cpp:93:31: warning: format specifies type 'int *' but the argument has type 'long long *' [-Wformat]
scanf("%d%d%d",&x,&y,&z);
~~ ^~
%lld
prog.cpp:94:18: error: expected expression
if (!ob[{x,y}])
^
prog.cpp:94:18: error: expected ']'
prog.cpp:94:17: note: to match this '['
if (!ob[{x,y}])
^
prog.cpp:99:16: error: expected expression
ob[{x,y}]=1;
^
prog.cpp:99:16: error: expected ']'
prog.cpp:99:15: note: to match this '['
ob[{x,y}]=1;
^
prog.cpp:100:16: error: expected expression
ob[{y,x}]=1;
^
prog.cpp:100:16: error: expected ']'
prog.cpp:100:15: note: to match this '['
ob[{y,x}]=1;
^
prog.cpp:101:17: error: expected expression
v[p-1]={z,{x,y}};
^
prog.cpp:123:24: error: expected expression
pq[x].push({-z,i});
^
prog.cpp:126:15: error: expected expression
if (c[{x,y}]==0) {
^
prog.cpp:126:15: error: expected ']'
prog.cpp:126:14: note: to match this '['
if (c[{x,y}]==0) {
^
prog.cpp:128:11: error: expected expression
c[{x,y}]=o;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
stdout