Submission #209226

#TimeUsernameProblemLanguageResultExecution timeMemory
209226mieszko11bBridges (APIO19_bridges)C++14
13 / 100
3087 ms8184 KiB
#include <bits/stdc++.h>

using namespace std;

using ii = pair<int, int>;

#define X first
#define Y second

int n, m;
vector<ii> G[50007];
int c[50007];
bool vis[50007];
int cnt;

void dfs(int w, int lim) {
	if(vis[w]) return;
	vis[w] = 1;
	cnt++;
	
	for(ii u : G[w])
		if(c[u.Y] >= lim)	
			dfs(u.X, lim);
}

int query(int w, int lim) {
	cnt  =0;
	memset(vis, 0, sizeof vis);
	dfs(w, lim);
	return cnt;
}



void update(int i, int v) {
	c[i] = v;
}

int main() {
	scanf("%d%d", &n, &m);
		
	for(int i = 1 ; i <= m ; i++) {
		int a,b, c;
		scanf("%d%d%d", &a, &b, &c);
		G[a].push_back({b, i});
		G[b].push_back({a, i});
		::c[i] = c;
	}
	
	int q;
	scanf("%d", &q);
	while(q--) {
		int t, a, b;
		scanf("%d%d%d", &t, &a, &b);
		if(t == 1)
			update(a, b);
		else
			printf("%d\n", query(a, b));
	}
	
	return 0;
}

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
bridges.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &t, &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...