이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
template<class T> inline bool chmin(T &a, T b){
if(a>b){a=b;return true;}
return false;
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){a=b;return true;}
return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;
int N,M;
vector<P>G[1005];
int from[1005],to[1005],idx1[1005],idx2[1005];
bool used[1005];
void dfs(int x,int y){
used[x]=true;
for(P i:G[x]){
if(!used[i.first]&&i.second>=y)dfs(i.first,y);
}
}
signed main(){
cin>>N>>M;
rep(i,M){
int a,b,c;cin>>a>>b>>c;a--;b--;
from[i]=a;idx1[i]=len(G[a]);
to[i]=b;idx2[i]=len(G[b]);
G[a].push_back({b,c});
G[b].push_back({a,c});
}
int Q;cin>>Q;
while(Q--){
int type;cin>>type;
if(type==1){
int a,b;cin>>a>>b;a--;
G[from[a]][idx1[a]].second=b;
G[to[a]][idx2[a]].second=b;
}else {
int a,b;cin>>a>>b;a--;
memset(used,0,sizeof(used));
dfs(a,b);
int ans=0;
rep(i,N)ans+=used[i];
cout<<ans<<endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |