# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
123270 |
2019-07-01T02:36:46 Z |
sams |
Dijamant (COI16_dijament) |
C++14 |
|
1619 ms |
11276 KB |
//COI dijament
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int, int> ii;
const int maxn = 1e3+10, inf = 0x3f3f3f3f;
struct node
{
int u, f, d;
};
int n, nd;
map<string, int> inh;
int t, pross[maxn], vis[maxn];
int sub[maxn][maxn];
vector<int> graph[maxn];
int dfs(int u)
{
vis[u] = 1;
pross[u] = 1;
for(int v: graph[u])
{
if(!vis[v])
{
if(dfs(v) == 0) return 0;
}
else if(pross[v] == 1) return 0;
}
pross[u] = 0;
return 1;
}
void init()
{
memset(pross, 0, sizeof pross);
memset(vis, 0, sizeof vis);
}
void debug()
{
for(int i = 1 ; i <= nd ; ++i)
{
if(graph[i].size() > 0) cout << i << ": \n ";
for(int u: graph[i]){
cout << u << ' ';
}
if(graph[i].size() > 0) cout << "\n\n";
}
}
int diamond(int u)
{
for(int i = 0 ; i < graph[u].size() ; ++i)
{
int a = graph[u][i];
for(int j = i + 1 ; j < graph[u].size() ; ++j)
{
int b = graph[u][j];
if(sub[b][a] == 0 && sub[a][b] == 0)
for(int k = 1 ; k <= u ; ++k)
if(sub[a][k] == 1 && sub[b][k] == 1) return 0;
}
}
return 1;
}
int main()
{
cin >> n;
for(int i = 0 ; i < n ; ++i)
{
string name, pt, s;
cin >> name >> pt;
int ok = 1;
if(inh[name] != 0) ok = 0;
vector<int> ad;
while(cin >> s && s != ";")
{
if(inh[s] == 0 || s == name) ok = 0;
else ad.push_back(inh[s]);
}
if(!ok) cout << "greska\n";
else
{
inh[name] = ++nd;
for(auto u: ad)
{
graph[nd].push_back(u);
sub[nd][u] = 1;
for(int i = 0 ; i < graph[u].size() ; ++i)
{
int v = graph[u][i];
sub[nd][v] = 1;
}
}
init();
ok = min(ok, dfs(nd));
if(!ok)
{
for(int i = 1 ; i <= n ; ++i)
{
sub[nd][i] = 0;
}
graph[nd].clear();
inh[name] = 0;
nd--;
cout << "greska\n";
continue;
}
ok = diamond(nd);
if(!ok)
{
for(int i = 1 ; i <= n ; ++i)
{
sub[nd][i] = 0;
}
graph[nd].clear();
inh[name] = 0;
nd--;
cout << "greska\n";
continue;
}/**/
cout << "ok\n";
}
}
}
Compilation message
dijament.cpp: In function 'int diamond(int)':
dijament.cpp:63:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < graph[u].size() ; ++i)
~~^~~~~~~~~~~~~~~~~
dijament.cpp:67:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = i + 1 ; j < graph[u].size() ; ++j)
~~^~~~~~~~~~~~~~~~~
dijament.cpp: In function 'int main()':
dijament.cpp:112:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < graph[u].size() ; ++i)
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
8 ms |
760 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
8 ms |
760 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1368 ms |
10276 KB |
Output is correct |
2 |
Correct |
1619 ms |
11276 KB |
Output is correct |
3 |
Correct |
444 ms |
4700 KB |
Output is correct |
4 |
Incorrect |
7 ms |
1272 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |