Submission #510609

#TimeUsernameProblemLanguageResultExecution timeMemory
510609amukkalirBridges (APIO19_bridges)C++17
13 / 100
54 ms5328 KiB
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define pii pair<int,int> 
#define fi first 
#define se second 
#define pb push_back 
#define mp make_pair

const int INF = 1e9+1000; 
const int nax = 1000; 
int n, m; 
int p[nax+5]; 
vector<pair<int,pii>> b; 

int par(int a) {
    return p[a] == a ? a : p[a] = par(p[a]); 
}

void  join(int a, int b) {
    p[par(a)] = par(b); 
}

signed main () {
    scanf("%d %d", &n, &m); 

    b.pb(mp(0,mp(0,0))); 
    for(int i=1; i<=m; i++) {
        int u, v, d; 
        scanf("%d %d %d", &u,&v,&d); 
        b.pb(mp(d,mp(u,v))); 
    }

    int q; scanf("%d", &q); 
    while(q--) {
        int tp; scanf("%d", &tp); 
        int x, w; scanf("%d%d", &x, &w); 

        if(tp==1) {
            b[x].fi = w; 
        } else {    
            for(int i=1; i<=n; i++) p[i] = i; 
            for(auto br : b) {
                int d = br.fi; 
                if(d < w) continue; 
                int u = br.se.fi; int v = br.se.se; 
                join(u, v); 
            }
            int c = 0; 
            for(int i=1; i<=n; i++) {
                if(par(i) == par(x)) c++; 
            }
            printf("%d\n", c); 
        }
    }
}

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bridges.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d %d", &u,&v,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:34:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     int q; scanf("%d", &q);
      |            ~~~~~^~~~~~~~~~
bridges.cpp:36:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         int tp; scanf("%d", &tp);
      |                 ~~~~~^~~~~~~~~~~
bridges.cpp:37:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         int x, w; scanf("%d%d", &x, &w);
      |                   ~~~~~^~~~~~~~~~~~~~~~
#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...