1 solutions
-
0
C++ :
#include <cstdio> #include <algorithm> #include <vector> #define F(x,y,z) for(int x=y;x<=z;x++) #define DF(x,y,z) for(int x=y;x>=z;x--) using namespace std; typedef long long ll; template <typename T> void read(T& x){ T pd=1; char ch=getchar(); x=0; while(ch<'0'||ch>'9'){ if(ch=='-') pd=-1; ch=getchar(); } while('0'<=ch&&ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } x*=pd; } int n,m,ans; vector<int>t[25]; int c[25][25]; bool vis[25]; void dfs(int k,int sum){ ans=max(ans,sum); vis[k]=true; F(i,0,(int)t[k].size()-1){ if(vis[t[k][i]]) continue; dfs(t[k][i],sum+c[k][t[k][i]]); } vis[k]=false; } int main(){ // freopen("598.in","r",stdin); // freopen("598.out","w",stdout); read(n); read(m); F(i,1,m){ int x,y,z; read(x); read(y); read(z); c[x][y]=c[y][x]=z; t[x].push_back(y); t[y].push_back(x); } F(i,1,n) dfs(i,0); printf("%d",ans); return 0; }
- 1
Information
- ID
- 970
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By