显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
void read(int &x)
{
int f=1;
x=0;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
x=x*f;
return;
}
struct PE
{
int U,V,W;
};
PE edge[500001];
int ls[100001],n,m,u,v,w,q,ans;
string X;
bool Function(PE X,PE Y)
{
return X.W<Y.W;
}
void Check(int l,int r)
{
ans=0x3f3f3f3f;
for(int i=1;i<=m;i++)
{
if(ls[edge[i].U]==l&&ls[edge[i].V]==r)
{
ans=edge[i].W;
return;
}
if(ls[edge[i].U]==r&&ls[edge[i].V]==l)
{
ans=edge[i].W;
return;
}
}
return;
}
int DJ()
{
freopen("seta.in","r",stdin);
freopen("seta.out","w",stdout);
read(n);
read(m);
for(register int i=1;i<=m;i++)
{
read(edge[i].U);
read(edge[i].V);
read(edge[i].W);
}
for(register int i=1;i<=n;i++)
{
ls[i]=1;
}
sort(edge+1,edge+1+m,Function);
read(q);
while(q--)
{
cin>>X;
if(X[0]=='A')
{
int L=X[3]-'A'+1,R=X[4]-'A'+1;
Check(L,R);
if(ans==0x3f3f3f3f)
{
printf("No Found!\n");
}
else
{
printf("%d\n",ans);
}
}
else
{
read(w);
int L=X[4]-'A'+1;
ls[w]=L;
}
}
return 0;
}
int SED=DJ();
int main()
{
;
}