记录编号 |
235068 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[SDOI 2012 DAY2]集合 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.384 s |
提交时间 |
2016-03-10 10:26:39 |
内存使用 |
7.84 MiB |
显示代码纯文本
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100050;
const int inf = 1e9;
int n, m, que;
struct edge {
int fr, to, v, ne;
bool operator < (const edge &b) const{
return v < b.v;
}
}e[maxn*5];
int be[maxn];
int head[maxn], tot;
inline void addedge(int a, int b, int c) {
++tot; e[tot].fr = a; e[tot].to = b; e[tot].v = c; e[tot].ne = head[a]; head[a] = tot;
}
inline int ask(int set_num_1, int set_num_2) {
for(int i = 1; i <= m; i++) {
if(
(be[e[i].fr] == set_num_1 && be[e[i].to] == set_num_2) ||
(be[e[i].fr] == set_num_2 && be[e[i].to] == set_num_1)
) {
return e[i].v;
}
}
return inf;
}
inline void handle(int tar, int set_num) {
be[tar] = set_num;
}
inline void read() {
scanf("%d %d", &n ,&m);
int a, b, c;
for(int i = 1; i <= n; i++) {
be[i] = 1;
}
for(int i = 1; i <= m; i++) {
scanf("%d %d %d", &a, &b, &c);
addedge(a, b, c);
}
sort(e+1, e+1+m);
scanf("%d", &que);
char tmp[10];
int tar;
int ans;
for(int i = 1; i <= que; i++) {
scanf("%s", tmp);
if(tmp[0] == 'A') {
ans = ask(tmp[3]-'A'+1,tmp[4]-'A'+1);
if(ans == inf) {
printf("No Found!\n");
}else {
printf("%d\n", ans);
}
}else {
scanf("%d", &tar);
handle(tar, tmp[4]-'A'+1);
}
}
}
int main() {
freopen("seta.in", "r", stdin);
freopen("seta.out", "w", stdout);
read();
return 0;
}