zoukankan      html  css  js  c++  java
  • csu oj Infected Computer 1427

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <stdio.h>
     4 #define max 20005
     5 #define ll long long
     6 using namespace std;
     7 
     8 struct G{
     9     int from;
    10     int to;
    11     ll time;
    12 }game[max];
    13 
    14 bool graf[max];
    15 
    16 bool cmp(G a,G b){
    17     return a.time < b.time;
    18 }
    19 int main()
    20 {
    21     int n,m;
    22     while(cin>>n>>m){
    23         for(int i = 0;i < max;i++){
    24             graf[i]=false;
    25             game[i].time=game[i].from=game[i].to=0;
    26         }
    27         graf[1]=true;
    28 
    29         for(int i = 0;i < m;i++){
    30             cin>>game[i].time>>game[i].from>>game[i].to;
    31         }
    32         sort(game,game+m,cmp);
    33 
    34         bool flag = false;
    35         for(int i = 0;i < m;i++){
    36             if(game[i].from==1){
    37                 flag = true;
    38                 //graf[game[i].to] = true;
    39             }
    40             if(flag&&graf[game[i].from]){
    41                 graf[game[i].to] = true;
    42             }
    43         }
    44         ll ans = 0;
    45         for(int i = 1;i <= n;i++){
    46             if(graf[i])ans++;
    47         }
    48         cout<<ans<<endl;
    49     }
    50     return 0;
    51 }

    如果非要给划分,我想应该是属于并查集一类的

    我要坚持一年,一年后的成功才是我想要的。
  • 相关阅读:
    基于opencv的摄像头的标定
    图像的角点简介
    周转时间和平均带权时间等
    QT各个版本的下载的地址
    参考文献格式
    sublime中的emmet插件的使用技巧
    sublime快捷键
    CSS布局居中
    Markdown 语法说明(简体中文版)
    sql作业题
  • 原文地址:https://www.cnblogs.com/tianxia2s/p/5424063.html
Copyright © 2011-2022 走看看