/*
.:*+=%@@@@@@=-.
.:=@#@@@#@@#######%==*.
.-=####@######%*-.....:%##%.
.*@###########%+:--........-%@-
.*@##############@+--.........-:%-
.+##################@==%%%%=+*:----+.
.-@####################%++%@@@@@=+**%@@*
.%###################@%%@@@###@%+:--%@@%.
-@###################@%%%%*::*%++:-----=@+.
-#####################@%=++++++*:-------.-=:
.+####################@%++*::-:::--::*:::***=:
.@#####################%=++*::::-:::++*=##@@#@-
..#####################@%%=++**:::::**+%@#@%%##-..
.%####################@@%=+++*+****::*=@######@.
.=######################@%%==+==++**+=@%@##@###+:...
-#######################@@@%%%===++=@@@%=++===*::--...
-########################@@@@@@@%==%%=++==@@:::::*:--.
..:#########################@@@@@@%%======++++::-..:-.--...
%#############################@###@%%@@%==%=%*----.--.::---.
#############################################*-:*:-:---*---- .
#############################################*--*--:---*---:-.
#############################################+--::--::-*::-::.
###########################################+:*-.---.---.:---*-..
###########################################**:-----------------.
##########################################@::**:--::::::--:::::-
###########################################:--:*:::::::::**::*+*
###########################################=:::***::::::**:::*+*
############################@@@@@@#########@+****::::********+++
############################@%%%%%@@@@@@@###%+***::::::::***+==+
############################@%%%%%%%%%%%@####=+:::-::::-::*+=%%+
#############################@%%%%%%%%%%@#####=::--------:*=%@%+
%###########################@%%%%==%%%%%%@##@#=:------..-:+%@@%=
----------------------------------------------
--------------------------------------------
----------------------------------------------
--------------------------------------------
----------------------------------------------
o###########oo
o##" ""##o
o#" "##
o#" "#o
#" ## ## "##
#" ##
# ################### #
# #
# #
# #
# #
# #
# #
#o #
"#o ##
"#o ##
"#o o#"
"#o ##
"#o o#"
"#ooo ooo#######oo
############### "######o
o###"" "###o # ###
o###o oooo ### oo####"
o###**# #**# ############"
""##""""""""""########### #
# oooooooo#"#** ## #
# # # # ** ## #
#o# #o# *****###ooo#
##
## o###o
## o##***##
o########## #***#**##o
o##" ""### #***##***#
o#######o ### oo#### ##**####*#
o##" ""#############"" ##****###
##" ## ##*##*###
## ### ##### ##
## ### # ## #
## ## #
## ##
## ###
## ###oo
### ""###
###
###
*/
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
//float __attribute__((aligned(32)))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
int mysqrt(ll x){
int l = 0, r = 1e9 + 1;
while (r - l > 1){
int m = (l + r) / 2;
if (m * (ll)m <= x)
l = m;
else
r = m;
}
return l;
}
mt19937 rnd(1337);
mt19937_64 rndll(12365);
ll AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;
ll myrand(){
ll ZR = (XR * AR + YR * BR + CR) % MODR;
XR = YR;
YR = ZR;
return ZR;
}
const int Mod = 1e9 + 7;
int bpow(int x, int y){
if (y == 0)
return 1;
if (y == 1)
return x;
int ret = bpow(x, y >> 1);
ret = (ret * (ll)ret) % Mod;
if (y & 1)
ret = (ret * (ll)x) % Mod;
return ret;
}
int bdiv(int x, int y){
return (x * (ll)bpow(y, Mod - 2)) % Mod;
}
void setmin(int &x, int y){
x = min(x, y);
}
void setmax(int &x, int y){
x = max(x, y);
}
void setmin(ll &x, ll y){
x = min(x, y);
}
void setmax(ll &x, ll y){
x = max(x, y);
}
int gcd(int a, int b){
return a ? gcd(b % a, a) : b;
}
const ll llinf = 2e18 + 100;
const double eps = 1e-9;
const int maxn = 5e5 + 100, maxw = 1e5 + 100, inf = 2e9 + 100, sq = 300, mod = 1e9 + 7, LG = 17;
int n, M, zap;
int quer[maxn];
int ans[maxn];
int p[maxn];
int rnk[maxn];
int get(int x){
return x == p[x] ? x : p[x] = get(p[x]);
}
void uni(int x, int y){
x = get(x);
y = get(y);
if (x == y)
return;
if (rnk[x] < rnk[y])
swap(x, y);
p[y] = x;
if (rnk[x] == rnk[y])
rnk[x]++;
}
vector<pair<int, int> > e[maxw];
pair<int, int> b[maxn];
int main()
{
#ifdef ONPC
//ifstream cin("a.in");
//ofstream cout("a.out");
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#else
//ifstream cin("gymnasts.in");
//ofstream cout("gymnasts.out");
//freopen("post.in", "r", stdin);
//freopen("post.out", "w", stdout);
#endif // ONPC
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
//cin >> n >> M >> zap;
scanf("%d%d%d", &n, &M, &zap);
for (int i = 0; i < M; i++){
int v, u, w;
//cin >> v >> u >> w;
scanf("%d%d%d", &v, &u, &w);
e[w].push_back(make_pair(v - 1, u - 1));
}
for (int i = 0; i < zap; i++)
/*cin >> quer[i]*/scanf("%d", &quer[i]), quer[i]--;
for (int i = 0; i < n; i++)
b[i] = make_pair(0, 1e5);
vector<vector<int> > q(maxw);
for (int its = 0; its <= LG; its++){
for (int i = 0; i < n; i++)
p[i] = i, rnk[i] = 0;
for (int i = 0; i <= 1e5; i++)
q[i].clear();
for (int i = 1; i < n; i++){
int l = b[i].first, r = b[i].second;
if (r - l > 1){
int m = (l + r) / 2;
q[m].push_back(i);
}
}
for (int i = 1e5; i > 0; i--){
for (auto ed : e[i])
uni(ed.first, ed.second);
for (auto j : q[i])
if (get(j) == get(0))
b[j].first = (b[j].first + b[j].second) / 2;
else
b[j].second = (b[j].first + b[j].second) / 2;
}
}
for (int i = 0; i < zap; i++)
printf("%d\n", b[quer[i]].second);
//cout << b[quer[i]].first << '\n';
}
Compilation message
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:220:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &M, &zap);
^
sightseeing.cpp:224:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &v, &u, &w);
^
sightseeing.cpp:228:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
/*cin >> quer[i]*/scanf("%d", &quer[i]), quer[i]--;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
5220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
120 ms |
10536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3507 ms |
79916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |