[做题笔记] 2016/12/1

1000. 1004. dijkstra算法

1001. 递归,每一个点出发的最大路径=max(它所连点中出发路径的最大值+边权值)

1002. 广度优先搜索同时标记即可

1003. 样例只有一个。

【代码】

1000.

// Problem#: 19818
// Submission#: 4937880
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
// Problem#: 19818
// Submission#: 4937837
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include 
#include 
#define INF 1000000
#define MAX 200
using namespace std;
 
int main()
{
    int arcs[MAX][MAX];
    bool isvisit[MAX];
    int min_weight[MAX];
 
    int N;
    int cases;
 
    cin >> cases;
 
    while (cases--)
    {
        cin >> N;
        memset(isvisit, false, sizeof(isvisit));
 
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                cin >> arcs[i][j];
 
        for (int i = 0; i < N; i++)
            min_weight[i] = arcs[0][i];
 
        isvisit[0] = true;
        int _min;
        int hold, result = 0, max_weight = 0;
        for (int i = 1; i < N; i++)
        {
            _min = INF;
             
            for (int j = 0; j < N; j++)
            {
                if (!isvisit[j] && min_weight[j] < _min)
                {
                    _min = min_weight[j];
                    hold = j;
 
                }
            }   
            max_weight = max(max_weight, _min);
            result += _min;
 
            isvisit[hold] = true;
 
            for (int j = 0; j < N; j++)
                if (!isvisit[j] && arcs[hold][j] < min_weight[j])
                    min_weight[j] = arcs[hold][j];
        }
 
        cout << max_weight << endl ;
        if (cases != 0)
            cout << endl;
    }
 
    return 0;
}                                 
1001.

// Problem#: 19819
// Submission#: 4937640
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include
#include
#include
#include
#include
using namespace std;


typedef struct edge
{
   int st;
   int en; 
   int we;
   edge( int a,int b,int c){st=a,en=b,we=c;}
}e;

vector E[10010];
bool vis[10010];

int dfs(int k)
{
   int i;
   int max=0;
   vis[k]=true;
   for( i=0; imax )
            max=E[k][i].we+temp;


        }

   }
   vis[k]=0;
   return max;
}
int main()
{
    int n,k,i,j,u,v,d;
    while(cin>>n>>k)
    {
        memset(vis,0,sizeof(vis));
        memset(E,0,sizeof(E));
        for(i=0; i>u>>v>>d;
      E[u].push_back(e(u,v,d));
      E[v].push_back(e(v,u,d));
        }
       cout<< dfs(k)<
1002.

// Problem#: 19820
// Submission#: 4937822
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
// Problem#: 4379  
// Submission#: 1121129  
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License  
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/  
// All Copyright reserved by Informatic Lab of Sun Yat-sen University  
#include   
#include   
#include   
using namespace std;  
  
int main()  
{  
    int n, m;  
    int i, j;  
    queue q;  
    int color[ 1001 ];  
    bool path[ 1001 ][ 1001 ];  
  
    memset( color, 0, sizeof( color ) );  
    memset( path, false, sizeof( path ) );  
  
    scanf( "%d%d", &n, &m );  
    while ( m-- ) {  
        scanf( "%d%d", &i, &j );  
        path[ i ][ j ] = true;  
        path[ j ][ i ] = true;  
    }  
  
    q.push( 1 );  
    color[ 1 ] = -1;  
    while ( !q.empty() ) {  
        i = q.front();  
        for ( j = 1; j <= n; j++ ) {  
            if ( path[ i ][ j ] ) {  
                if ( color[ i ] == color[ j ] ) {  
                    printf( "no\n" );  
                    return 0;  
                }  
                if ( color[ j ] == 0 ) {  
                    q.push( j );  
                    color[ j ] = ( color[ i ] == 1 ? -1: 1 );  
                }  
            }  
        }  
        q.pop();  
    }  
    printf( "yes\n" );  
  
    return 0;  
  
}                                 



你可能感兴趣的:(Sicily快乐之旅)